我在我的应用程序上使用webservices没有问题,但是这个特定的json调用不起作用,我无法调试它。
使用萤火虫我看到了:
<script type="text/javascript">
$(function() {
$('#btnBreakfast').click(function(){
$.ajax({
typeof: "POST",
contentType: "application/json; charset=utf-8",
url: "/service1.asmx/SaveFoodEntry",
data: JSON.stringify({ "PatientID": "919", "ClinicID": "231", "txtDate": "", "foodname": $('#txtBreakfast').val(), "selecteditem": $('#ddlBreakfastServings option:selected').text(), "value": $('#ddlBreakfastServings option:selected').val(), "foodquantity": $('#txtBreakfastQuantity').val(), "MealTime": "Breakfast" }),
dataType: 'json',
async: true,
success: function(msg) {
alert('Success!');
},
error: function(msg) {
alert('Error!');
}
});
});
});
</script>
我通过传入相同的值直接测试Web服务,它工作正常。
以下是我在firebug中看到的内容:
Request URL:https://mydomain.com/service1.asmx/SaveFoodEntry?{%22PatientID%22:%221119%22,%22ClinicID%22:%2211%22,%22txtDate%22:%22%22,%22foodname%22:%22Lard%22,%22selecteditem%22:%22tbsp%22,%22value%22:%2212.8%22,%22foodquantity%22:%221%22,%22MealTime%22:%22Breakfast%22}
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Content-Type:application/json; charset=utf-8
Referer:https://synergyweight.com/ToolsHome.aspx
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
{"PatientID":"919","ClinicID":"231","txtDate":"","foodname":"Lard","selecteditem":"tbsp","value":"12.8","foodquantity":"1","MealTime":"Breakfast"}:
预览和响应没有显示任何内容。
我很困惑,因为这是萤火虫中的正常网络响应:
Request URL:/service1.asmx/GetServingInfo
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:21
Content-Type:application/json; charset=UTF-8
Cookie:ASP.NET_SessionId=pqmfvm12pwdx1gx1nucv420c; .ASPXAUTH=EAE6B9BB55FC11F254373A09876B9C447BEE338B976B6BB2F864A161BC1D1179B09A30F9B3D8494FD256E27D93E1CB41D8EFFFC7FB8E2F2E0B2FF2008A05694DABC00C2C743A30B599BD647129C4D7643A1C8E854C8AC7F01C6CAB073C0A7E61B1113EF9C26C371E6FCAA3E00F0BF2099A5DCF16623B9A8C93FD1DB4773C8650
Host:mydomain.com
Origin:https://mydomain.com
Referer:https://mydomain.com/Home.aspx
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payloadview source
{prefixText:Lard}
prefixText: "Lard"
Response Headersview source
Cache-Control:private, max-age=0
Content-Length:25
Content-Type:application/json; charset=utf-8
Date:Fri, 13 Sep 2013 23:45:44 GMT
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
有人能指出我正确的方向吗?