ajax jquery不工作,未进入成功状态
我有一个html页面试图调用下面的ajax jquery调用。如果我将url放在浏览器中,我会将数据取回。第一个警报起作用,显示我们已进入。成功中的警报永远不会弹出,它会转到错误警报。我的代码有什么问题吗ajax jquery不工作,未进入成功状态,jquery,Jquery,我有一个html页面试图调用下面的ajax jquery调用。如果我将url放在浏览器中,我会将数据取回。第一个警报起作用,显示我们已进入。成功中的警报永远不会弹出,它会转到错误警报。我的代码有什么问题吗 function GetAllStaff() { alert('we R IN'); $.ajax({ type: "GET", url:"http://MyServer/MyService/api/StaffSearch/Ge
function GetAllStaff() {
alert('we R IN');
$.ajax({
type: "GET",
url:"http://MyServer/MyService/api/StaffSearch/GetAllStaff",
data: "{}",
contentType: "application/json; charset=utf-8",
cache: false,
dataType: "json",
success: function(data) {
alert('hello world');
},
error: function(msg) {
alert('This is the error: ' + msg.d);
}
});
}
这是一个跨域问题,我刚刚添加了行$.support.cors=true;它解决了这个问题。只要删除数据线,它就会工作。 查找ajax请求问题的一个好方法是使用FireBug
$.ajax({
type: "GET",
url:"http://MyServer/MyService/api/StaffSearch/GetAllStaff",
contentType: "application/json; charset=utf-8",
cache: false,
dataType: "json",
success: function(data) {
alert('hello world');
},
error: function(msg) {
alert('This is the error: ' + msg.d);
}
});
页面是在Web服务器上运行还是在本地运行?返回了什么错误?您得到了什么错误?
数据:“{}”,
您得到的内容真的是json吗?如果服务器想要一个空的json对象,它应该是这样的:data:{passedData:{},