使用webservice调用获取项目

问题描述:

我试图从数据虚拟化视图中使用JQuery中的webservices检索值列表。这是我现在所掌握的,并且我从alert(xhr.error)中得到了error。你们能帮助我解决任何我可能忽略的明显事情吗?非常感谢使用webservice调用获取项目

<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> 
+0

似乎'xhr.error'是一个'function'。尝试用'xhr.error()' – Red

+0

取代它或者或许警告错误参数:'alert(error)' 同样在成功处理程序'alert(msg)'而不是'$(msg).text() '。 –

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

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

,如果你是刚刚从服务方法的数据,你可以做 “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

你得到jQuery中的wsdl(= soap webservice)?你必须使用SoapClient,例如php Soapclient。

并再次调用你的Ajax:你的PHP脚本中

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

认沽用户名/密码,并使用SoapClient的:

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

你可以尝试一个jQuery SoapClient的:https://github.com/doedje/jquery.soap

但是,如果这是公共应用程序,这是禁止的,它会暴露您的web服务的用户/密码,使用p HP,并返回你自己的JSON。