Javascript &引用;访问控制允许原点不允许原点为空。”;使用jQuery调用web服务时出错

Javascript &引用;访问控制允许原点不允许原点为空。”;使用jQuery调用web服务时出错,javascript,web-services,jquery,Javascript,Web Services,Jquery,我创建了一个web服务,它返回一些数据,并尝试使用jquery访问它,但控制台显示以下错误: OPTIONS http://localhost:56018/PhoneWebServices.asmx?op=GetMyChildren 405 (Method Not Allowed) jQuery.ajaxTransport.sendjquery-1.7.1.js:8102 jQuery.extend.ajaxjquery-1.7.1.js:7580 LoginButton_onclick

我创建了一个web服务,它返回一些数据,并尝试使用jquery访问它,但控制台显示以下错误:

    OPTIONS http://localhost:56018/PhoneWebServices.asmx?op=GetMyChildren 405 (Method Not Allowed)
jQuery.ajaxTransport.sendjquery-1.7.1.js:8102
jQuery.extend.ajaxjquery-1.7.1.js:7580
LoginButton_onclickindex.html:26
(anonymous function)index.html:59
onclickindex.html:60
XMLHttpRequest cannot load http://localhost:56018/PhoneWebServices.asmx?op=GetMyChildren. Origin null is not allowed by Access-Control-Allow-Origin.
我假设405错误是由于“不允许原点为空”错误造成的。 以下是我迄今为止采取的步骤:

  • 创建了网站(正在工作)并在网站中创建了web服务
  • 我通过在浏览器中键入url来测试web服务,它可以正常工作
  • 创建了一个移动web应用程序,该应用程序尝试调用web服务,但显示了上述错误
我的客户端(移动应用程序代码):


文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
函数ondevicerady(){
}
函数LoginButton_onclick(){
var email=document.getElementById(“EmailBox”).value;
var pass=document.getElementById(“PasswordBox”).value;
$.ajax({
类型:“POST”,
contentType:“应用程序/json;字符集=utf-8”,
url:“http://localhost:56018/PhoneWebServices.asmx?op=GetMyChildren",
数据:“{”email:“'+email+”,“密码:“'+pass+”}”,
数据类型:“json”,
成功:GetChildrenSuccess,
失败:GetChildrenFailed
});
}
函数GetChildrenSuccess(响应){
var children=eval(“(“+response.d+”)”);
var-child;
用于(儿童中的儿童){
$('#ResultsDiv').innerHTML=“ID:+child.ID+”名称:“+child.Name+”姓氏:“+child.姓氏+”\r\n”;
}
}
函数GetChildrenFailed(错误){
document.getElementById('ResultsDiv').innerHTML=“Error”;
}
我在想,可能是因为我没有用IIS发布网站或Web服务,我需要这样做吗?即使url在输入浏览器时起作用,我也不确定它在客户端代码中是否应该相同


我对网络编程非常陌生,因此,如果您知道有什么问题,请简单解释,非常感谢您的帮助。

如果您通过本地网络服务器运行文件,而不仅仅是使用浏览器打开HTML文件,那么问题很可能会消失。当您只打开文件,而不通过web服务器时,您不会得到一个源域-因此错误消息是源域为空。

因此,为了解决这个问题,我需要在IIS中托管我的网站吗?@Matt Yes,IIS或您选择的其他web服务器。
<script type="text/javascript">

      document.addEventListener("deviceready", onDeviceReady, false);


      function onDeviceReady() {

      }

      function LoginButton_onclick() {
      var email=document.getElementById("EmailBox").value;
      var pass=document.getElementById("PasswordBox").value;
      $.ajax({
          type: "POST",
          contentType: "application/json; charset=utf-8",
          url: "http://localhost:56018/PhoneWebServices.asmx?op=GetMyChildren",
          data: '{ "email" : "' + email + '", "password": "' + pass + '" }',
          dataType: "json",
          success: GetChildrenSuccess,
          failure: GetChildrenFailed
      });
  }

  function GetChildrenSuccess(response) {
      var children = eval('(' + response.d + ')');
      var child;
      for(child in children) {
          $('#ResultsDiv').innerHTML = "ID: "+child.ID+ " Name: "+child.Name+" Surname: "+child.Surname+" \r\n";
      }
  }

  function GetChildrenFailed(error) {
      document.getElementById('ResultsDiv').innerHTML = "Error";
  }

  </script>