我有以下代码来进行 jsonp 调用。
var contacts;
$.ajax({
url: "http://localhost:51973/Service1/GetContacts",
type: "GET",
async: false,
data: { companyName: company },
dataType: "jsonp",
success: function(data) {
contacts = data;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("error " + XMLHttpRequest.statusText);
}
});
但无论出于何种原因,我都将联系人视为未定义。我使用 fiddler 检查了流量,发现它得到了以下响应。
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 09 Apr 2012 14:52:33 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 100
Cache-Control: private
Content-Type: application/x-javascript
Connection: Close
jQuery17107471185381512466_1333983153278([{"Email":"john@test.com","Name":"Test Company"}]);
那么为什么没有正确设置联系人变量?