【发布时间】:2010-12-29 21:30:51
【问题描述】:
这是一个有趣的问题:
我有一些看起来像这样的 jQuery:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://localhost:63056/Service1.asmx/PrintOrderRecieptXml",
data: {
"CouponCode": "TESTCODE",
"Subtotal": 14.2600,
"ShippingTotal": 7.5000,
"TaxTotal": 0.0000,
"GrandTotal": 21.7600,
"OrderItemCollection": [{
"Total": 14.2600,
"Qty": 250
}]
},
dataType: "json",
contentType: "application/json",
error: function(xhr, msg) {
alert(xhr.statusText);
}
});
});
现在,我遇到的问题是它正在发送请求,但 Web 服务没有正确处理它。在 IE 中,我收到一个带有“内部服务器错误”的警告框,而在 FireFox 中,我收到一个里面没有任何内容的警告框。
奇怪的是,当我使用 IE 时,我的事件日志中没有出现错误事件,但是使用 firefox 我得到了(弄清楚为什么会这样):
“异常消息:无法识别请求格式,因为 URL 意外以 '/PrintOrderRecieptXml 结尾”
我浏览了一些,发现有时您必须添加:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost" />
<add name="HttpPostLocalhost"/>
</protocols>
</webServices>
到您的 Web.Config,我这样做了,但没有帮助。有趣的是,Web 服务可以与 SOAP 或发送查询字符串一起正常工作,但不能与 JSON 一起工作。
有什么想法吗?
【问题讨论】:
标签: asp.net jquery web-services json