0

我正在尝试使用 JQuery 中的 web 服务从数据虚拟化视图中检索值列表。这就是我现在所拥有的,我错误从警报(xhr.error)中得到。你们中的任何人都可以帮助我解决我可能忽略的任何明显的事情吗?非常感激

 <script src="/jquery-1.11.1.js"></script>
 <script src="/jquery.SPServices-2014.02.min.js"></script>
 <script type="text/javascript" language="javascript">

 $(document).ready(function() {
 $.ajax({
     type: "POST",
     url: "http://xxx/soap11/ValidateSourceCode?wsdl",
 username: "xyz", 
     password: "xyz",
     dataType: "xml",
     data: {},
     processData: false,
     contentType:"text/xml; charset=\"utf-8\"",
     success: function (msg) {
          alert($(msg).text());
          //console.log($(msg).text());
     },
     error: function(xhr, status, error){
              alert(xhr.status);
              alert(xhr.error);

      }
    }); });


  </script>
4

3 回答 3

0

查看调试器中的网络选项卡。由于同源策略,您可能会收到 400 错误。这基本上意味着您不能向与托管应用程序的服务器不同的服务器发出 ajax 请求。

https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

于 2017-04-24T14:27:46.677 回答
0

如果您只是从服务方法中获取数据,则可以执行“GET”

$.ajax({
    type: "GET",
    url: "http://xxx/soap11/ValidateSourceCode?wsdl",
    data: {},
    contentType:"text/xml; charset=\"utf-8\"",
    success: jqSuccess,
    error: jqError
});

或者您可以尝试使用 jquery.soap https://github.com/doedje/jquery.soap/blob/master/README.md

于 2017-04-25T14:23:14.363 回答
0

您在 jQuery 中获得了 wsdl (=soap webservice)?您必须使用 SoapClient,例如 php Soapclient。

并再次调用您的 ajax :

$.ajax({
    type: "GET",
    url: "/api/yourLocalSoapClient.php",
    data: {query:'testApi'},
    contentType:"text/xml; charset=\"utf-8\"",
    success: jqSuccess,
    error: jqError
});

将用户名/密码放入您的 php 脚本中,然后使用 SoapClient:

http://php.net/manual/fr/class.soapclient.php

您可以尝试一个 jQuery 肥皂客户端:https ://github.com/doedje/jquery.soap

但是如果它是一个公共应用程序,这是被禁止的,它会暴露你的 web 服务的用户/密码,使用 php,并返回你自己的 json。

于 2017-04-26T13:26:53.537 回答