phonegap错误中ajax调用SOAP Web服务

phonegap错误中ajax调用SOAP Web服务,ajax,web-services,cordova,soap,ripple,Ajax,Web Services,Cordova,Soap,Ripple,我在使用Phonegap制作的应用程序中尝试设置一个工作的web服务时遇到问题。我需要从现有的web服务获取数据。我发现,通过使用一个简单的ajax请求,这应该是可行的。我没有正确使用ajax请求吗 我尝试调用的web服务可以在以下位置找到: 编辑:我对它进行了测试,正在取回我的xml文件,这个网站是如何工作的 我在ripple emulator中工作,所以我有一个跨域代理。 我怀疑我的请求标题可能已关闭 我得到的错误: 加载资源失败:服务器响应状态为400(错误请求)(10:26:26:851

我在使用Phonegap制作的应用程序中尝试设置一个工作的web服务时遇到问题。我需要从现有的web服务获取数据。我发现,通过使用一个简单的ajax请求,这应该是可行的。我没有正确使用ajax请求吗

我尝试调用的web服务可以在以下位置找到:

编辑:我对它进行了测试,正在取回我的xml文件,这个网站是如何工作的

我在ripple emulator中工作,所以我有一个跨域代理。 我怀疑我的请求标题可能已关闭

我得到的错误: 加载资源失败:服务器响应状态为400(错误请求)(10:26:26:851 |错误,网络) 在

(我无法公开我的登录代码)

我的测试html文件:

<html>
    <head>
        <title>Calling Web Service from jQuery</title>
        <script type="text/javascript"            src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js">
</script>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#btnCallWebService").click(function(event) {
                    var wsUrl = "http://ws.swinggift.com/SGServices.asmx?op=GetVouchers";

                    var soapRequest =
                            '<?xml version="1.0" encoding="utf-8"?>' +
                            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                            '<soap:Body>' +
                            '<GetVouchers xmlns="http://tempuri.org/">' +
                            '<logoncode>ICantGiveYouThis</logoncode>' +
                            '</GetVouchers>' +
                            '</soap:Body>' +
                            '</soap:Envelope>';

                    $.ajax({
                        type: "POST",
                        url: wsUrl,
                        contentType: "text/xml; charset=utf-8",
                        dataType: "xml",
                        crossDomain: true,
                        data: soapRequest,
                        beforeSend: function(XMLHttpRequest) {
                            XMLHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                            XMLHttpRequest.setRequestHeader("SOAPAction", "http://tempuri.org/GetVouchers");
                            XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
                        },
                        success: processSuccess,
                        error: processError
                    });
                });
            });

            function processSuccess(data, status, req) {
                if (status === "success")
                    $("#response").text($(req.responseXML));
            }

            function processError(data, status, req) {
                console.log(req.responseText + " " + status);
            }

        </script>
    </head>
    <body>
        <h3>
            Calling Web Services with jQuery/AJAX
        </h3>
        <input id="btnCallWebService" value="Call web service" type="button" />
        <div id="response" >
        </div>
    </body>
</html>

从jQuery调用Web服务
$(文档).ready(函数(){
$(“#btnCallWebService”)。单击(函数(事件){
var wsUrl=”http://ws.swinggift.com/SGServices.asmx?op=GetVouchers";
var soapRequest=
'' +
'' +
'' +
'' +
“我能给你这个”+
'' +
'' +
'';
$.ajax({
类型:“POST”,
url:wsUrl,
contentType:“text/xml;charset=utf-8”,
数据类型:“xml”,
跨域:是的,
数据:soapRequest,
beforeSend:函数(XMLHttpRequest){
setRequestHeader(“内容类型”,“text/xml;charset=utf-8”);
setRequestHeader(“SOAPAction”http://tempuri.org/GetVouchers");
setRequestHeader(“接受”,“应用程序/xml,text/xml,*/*”;
},
成功:成功,,
错误:processError
});
});
});
函数processSuccess(数据、状态、请求){
如果(状态==“成功”)
$(“#响应”).text($(req.responseXML));
}
功能处理错误(数据、状态、请求){
console.log(req.responseText+“”+状态);
}
使用jQuery/AJAX调用Web服务
谢谢

编辑: 我不知道这是否有帮助,但若我用这段代码做一个“GET”,若我请求响应文本,我会得到HTML格式的网页

<html>
    <head>
        <title>SOAP JavaScript Client Test</title>

        <!-- jQuery / jQueryMobile Scripts -->
            <script src="js/jquery-1.9.1.min.js"></script>
            <script src="js/jquery.mobile-1.3.1.min.js"></script>

        <script type="text/javascript">
            function soap() {
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open('GET', 'http://ws.swinggift.com/SGServices.asmx?op=GetVouchers', true);

                // build SOAP request
                var sr =
                    '<?xml version="1.0" encoding="utf-8"?>' +
                                '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                                '<soap:Body>' +
                                '<GetVouchers xmlns="http://tempuri.org/">' +
                                '<logoncode>something</logoncode>' +
                                '</GetVouchers>' +
                                '</soap:Body>' +
                                '</soap:Envelope>';

                xmlhttp.onreadystatechange = function () {
                    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
                            console.log('done' + xmlhttp.responseText);
                            $("#response").text($(xmlhttp.responseXML));
                        }
                    };

                // Send the POST request
                xmlhttp.setRequestHeader('Content-Type', 'text/xml');
                xmlhttp.setRequestHeader("Accept", "application/xml, text/xml, */*");
                xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/GetVouchers");
                xmlhttp.send(sr);
                // send request
                // ...
            }
        </script>
    </head>
    <body>
        <form name="Demo" action="" method="post">
            <div>
                <input type="button" value="Soap" onclick="soap();" />
                <div id="response" >
            </div>
            </div>
        </form>
    </body>
    </html>

soapjavascript客户端测试
函数soap(){
var xmlhttp=new XMLHttpRequest();
open('GET','http://ws.swinggift.com/SGServices.asmx?op=GetVouchers",对),;
//生成SOAP请求
var sr=
'' +
'' +
'' +
'' +
“有东西”+
'' +
'' +
'';
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
log('done'+xmlhttp.responseText);
$(“#响应”).text($(xmlhttp.responseXML));
}
};
//发送POST请求
setRequestHeader('Content-Type','text/xml');
setRequestHeader(“接受”,“应用程序/xml,text/xml,*/*”;
setRequestHeader(“SOAPAction”http://tempuri.org/GetVouchers");
xmlhttp.send(sr);
//发送请求
// ...
}

尝试设置
processData:false
。默认情况下,此标志为true,jQuery正在将XML转换为字符串


这是一个模拟器问题。。。现在使用上面的代码。

谢谢您的回答,但不幸的是,我仍然收到相同的错误。不过我会继续尝试你的贡献。你需要修改Ripple proxy.js。见此帖:
$.ajax({
                    type: "POST",
                    url: wsUrl,
                    contentType: "text/xml; charset=utf-8",
                    dataType: "xml",
                    crossDomain: true,
                    data: soapRequest,
                    processData: false,
                    beforeSend: function(XMLHttpRequest) {
                        XMLHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
                        XMLHttpRequest.setRequestHeader("SOAPAction", "http://tempuri.org/GetVouchers");
                        XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
                    },
                    success: processSuccess,
                    error: processError
                })