.ajax()中的成功函数不会执行

时间:2011-11-03 18:07:35

标签: json jquery

当我使用Firebug进行调试时,我看到控件在成功后跳转到错误部分。我无法找出出了什么问题。有人可以指出这个代码有什么问题。

$(function(){     
     $.ajax({
                type: "POST",
                url: "service/MyService.asmx/GetAsgInfo",
                data: "{id: " + parseInt($('#AsgId').val()) + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                   // var s = eval('(' + msg.d + ')');
                         alert(msg.d[0].SubmittedCount);
                        },
                error: function (e) {
                    alert("error : " + e);
                }
            });
});

POST:

{id: 5301}

回应:

       {"d":[{"__type":"Proxies.AFARServiceRef.AssignmentInfo","ExtensionData":
    {},"AssignDate":"\/Date(1319526000000)\/","AssignFileName":null,"ClaimId":"MH001025","ClaimantName":"Deborah C Plaid","FirstContactDate":"\/Date(1319526000000)\/","FirstContactTime":
{"Ticks":420000000000,"Days":0,"Hours":11,"Milliseconds":0,"Minutes":40,"Seconds":0,"TotalDays":
0.4861111111111111,"TotalHours":11.666666666666666,"TotalMilliseconds":42000000,"TotalMinutes":700,"TotalSeconds":42000},"Id":5301,"InspectionDate":"\/Date(1319612400000)\/","StatusId":1,
"SubmittedCount":4,"UploadedCount":14}]}

2 个答案:

答案 0 :(得分:1)

请尝试使用complete:

,而不是使用成功和错误函数
complete: function(jqXHR, textStatus) {
  alert(textStatus);
}

答案 1 :(得分:0)

我在处理json方面遇到了类似的问题,结果发现我没有在服务器端正确设置内容类型。甚至有效的json有时会在标记为“text / plain”甚至“text / json”的响应中导致奇怪的错误。确保您的内容类型正确。