ajax jquery不工作,不进入成功

问题描述:

我有一个HTML页面,试图调用下面的ajax jquery调用。如果我把这个url放到浏览器中,我就会得到数据。第一个警报工作,显示我们R IN。成功警报永远不会弹出,它会转到错误警报。我的代码有什么问题吗?ajax jquery不工作,不进入成功

 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); 
     } 
    }); 
} 
+1

该页面是在Web服务器上运行还是在本地运行?什么错误返回? – 23tux 2013-03-18 17:07:06

+2

你得到了什么错误? – mindandmedia 2013-03-18 17:07:06

+0

我在本地运行它,错误说undefined – user1220099 2013-03-18 17:07:48

这是一个跨域问题,我只是添加了行$ .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); 
     } 
    }); 
+0

这是一个跨域问题... – user1220099 2013-03-19 17:54:22