Jquery,无法连接到Web服务 - 404错误

时间:2016-07-20 11:16:27

标签: jquery web-services

我有一个带网址的网络服务: http://www.m-hakehilot.co.il/kehila_search/kehilot/retrieve.json[ ^]

当我在SoapUI软件中测试它时,它似乎运行良好。 在SoapUI中,我将服务类型配置为REST,将方法配置为POST。

之后,我尝试在ajax代码中使用它,但是我得到了404(未找到)错误。 我的ajax代码:

$.ajax({
  url: "http://www.m-hakehilot.co.il/kehila_search/kehilot/retrieve.json",
  type: 'post',
  dataType: 'json',
  error: function (XMLHttpRequest, textStatus, errorThrown) {
     console.log('get kehilot - error details:');
     console.log('XMLHttpRequest: ' + JSON.stringify(XMLHttpRequest));
     console.log('textStatus: ' + JSON.stringify(textStatus));
     console.log('errorThrown: ' + JSON.stringify(errorThrown));

     return [];
  },
  success: function (data) {
 //DO SOMETHING

  }
});

任何帮助?

提前致谢!

2 个答案:

答案 0 :(得分:0)

如果您检查控制台,则会看到此错误:XMLHttpRequest无法加载http://www.m-hakehilot.co.il/kehila_search/kehilot/retrieve.json。 No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' http://null.jsbin.com'因此不允许访问..您需要在您的Web服务上启用CORS。 - Rory McCrossan 7月20日11:20

答案 1 :(得分:0)

如果您检查控制台,则会看到此错误:

  

XMLHttpRequest无法加载http://www.m-hakehilot.co.il/kehila_search/kehilot/retrieve.json。 No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' http://null.jsbin.com'因此不允许访问..

您需要在网络服务上启用CORS。