Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用javascript客户端访问远程web服务_Javascript_.net_Json_Web Services - Fatal编程技术网

无法使用javascript客户端访问远程web服务

无法使用javascript客户端访问远程web服务,javascript,.net,json,web-services,Javascript,.net,Json,Web Services,我试图使用javascript访问.net webservice,但出现以下错误: 跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、https、chrome扩展资源 以下是java脚本代码: var v = {"name":"zain", "password":"abc" } // alert("wat"); $.ajax({ type:

我试图使用javascript访问.net webservice,但出现以下错误:

跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、https、chrome扩展资源

以下是java脚本代码:

    var v = {"name":"zain",
            "password":"abc"
            }
 //           alert("wat");
            $.ajax({
                type: "POST",
                url: "webcare.azurewebsites.net/WCService.asmx/GetParent",
                data: JSON.stringify(v),
                contentType: "application/x-www-form-urlencoded",
                dataType: "json",
                success: OnSuccess,
                error: OnError
                            });

        }
        function OnSuccess(data, status)
        {
           alert("success: "+data.d);
        }

        function OnError(request, status, error)
        {
            alert("error: "+request.statusText);
        }
a根据一个解决方案,该解决方案说在我的web服务旁边添加一个clientaccesspolicy.xml文件,但仍然给出相同的错误。 以下是我在clientaccesspolicy.xml中添加的代码

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="SOAPAction">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>


您还需要在适当的位置有一个跨域xml文件。查找“使用crossdomain.xml文件允许跨域访问”。按照那篇文章中的说明去做

试试
http://webcare.azurewebsites.net/WCService.asmx/GetParent
对于URL,是否需要SOAP请求(来自XML文件)?因为您希望ajax调用中的响应是JSON。@YuriyGalanter我添加的http://now错误已更改为:请求的资源上不存在“Access Control Allow Origin”头。因此,不允许访问源“null”。响应的HTTP状态代码为500。@不,它需要json结果。服务器必须允许CORS请求。这是使用标题完成的。我也这样做了。仍在获取
internet服务器错误500