2
我有以下的asmx服务调用ASMX服务从JavaScript
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class DinnerService : System.Web.Services.WebService
{
List<Dinner> dinners;
public DinnerService()
{
dinners = new List<Dinner>();
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public Dinner HelloWorld()
{
var dinner = new Dinner { DinnerID = 1, Host = "Ahsan", RSVP = "Some People", Venue = "Lahore" };
return dinner;
}
}
和IM从jQuery的调用它在网页表单的页面加载事件如下
$(function() {
$.ajax({
type: 'post',
url: 'http://localhost:1901/DinnerService.asmx/HelloWorld',
dataType: 'json',
data:{},
contentType: "application/json; charset=utf-8",
success: function (data) {
$('#res').html(data.d.DinnerID);
alert(data.d.Host);
}
});
});
它工作正常,在IE浏览器,但在Firefox和铬它显示内部服务器错误和响应就像
Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'
这对我来说很奇怪w它在一个浏览器上工作,而不在其他人上工作。我正在使用Visual Studio 2010和.NET 3.5进行该服务。对于这个特殊情况,去WCF不是选项。互联网上的回应无法帮助我解决问题。任何人都可以解释究竟发生了什么吗?
您是否试过这种解决方案? http://stackoverflow.com/questions/657313/request-format-is-unrecognized-for-url-unexpectedly-ending-in – 2012-02-27 11:01:49
有很多问题与网络上类似的标题,但他们不会遇到问题在一个特定浏览器。此外,我在服务项目的web.config中找不到''部分 –
2012-02-27 11:04:41
如果您的web.config中没有部分,只需在部分下添加一个部分即可。 –
jmaglio
2012-02-27 14:56:26