通过PhoneGap的错误阿贾克斯SOAP Web服务调用 [英] SOAP webservice call by ajax in phonegap error
问题描述
我在遇到试图建立在我的应用程序工作的Web服务我使用PhoneGap的制作问题。我需要从现有的Web服务中获取数据。我发现,通过使用一个简单的Ajax请求,这应该是工作。我不能使用Ajax请求是否正确?
Web服务,我试图调用可以在这里找到: HTTP://ws.swinggift。 COM / SGServices.asmx
编辑:我测试的 http://wsdlbrowser.com/ ,我让我的xml文件回,请问这个网站的工作?
我在纹波仿真工作,所以我有一个跨域代理。 我怀疑我的请求头可能会关闭?
错误我收到: (|错误,网络851:26:26 10):未能加载资源的服务器以400(错误请求)状态回应 在<一个href="https://rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//ws.swinggift.com/SGServices.asmx%3Fop%3DGetVouchers" rel="nofollow">https://rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//ws.swinggift.com/SGServices.asmx%3Fop%3DGetVouchers
(我不能让我的登录code公众)
我的测试HTML文件:
&LT; HTML&GT;
&LT; HEAD&GT;
&LT;冠军&GT;从jQuery和LT调用Web服务; /标题&GT;
&LT;脚本类型=文/ JavaScript的SRC =http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js&GT;
&LT; / SCRIPT&GT;
&LT;脚本类型=文/ JavaScript的&GT;
$(文件)。就绪(函数(){
$(#btnCallWebService)。点击(函数(事件){
VAR wsUrl =http://ws.swinggift.com/SGServices.asmx?op=GetVouchers;
VAR SOA prequest =
'&LT; XML版本=1.0编码=UTF-8&GT;? +
'&LT;肥皂:信封的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =http://www.w3.org/2001/XMLSchema的xmlns:肥皂= http://schemas.xmlsoap.org/soap/envelope/"> +
'&LT;肥皂:身体与GT; +
'&LT; GetVouchers的xmlns =http://tempuri.org/&GT; +
'&LT;登录code取代; ICantGiveYouThis&LT; /登录code基 +
'&LT; / GetVouchers&GT; +
'&LT; / SOAP:身体与GT; +
'&LT; /肥皂:信封&GT;';
$阿贾克斯({
键入:POST,
网址:wsUrl,
的contentType:为text / xml;字符集= UTF-8,
数据类型:XML,
跨域:真正的,
数据:SOA prequest,
beforeSend:功能(XMLHtt prequest){
XMLHtt prequest.setRequestHeader(内容类型,为text / xml;字符集= UTF-8);
XMLHtt prequest.setRequestHeader(SOAPAction的,http://tempuri.org/GetVouchers);
XMLHtt prequest.setRequestHeader(接受,应用程序/ XML,文本/ XML,* / *);
},
成功:processSuccess,
错误:的processError
});
});
});
功能processSuccess(数据,状态,REQ){
如果(状态===成功)
$(#响应)文本($(req.responseXML))。
}
函数的processError(数据,状态,REQ){
的console.log(req.responseText ++状态);
}
&LT; / SCRIPT&GT;
&LT; /头&GT;
&LT;身体GT;
&LT; H3&GT;
调用Web服务使用jQuery / AJAX
&LT; / H3&GT;
&LT;输入ID =btnCallWebService值=调用Web服务类型=按钮/&GT;
&LT; DIV ID =响应&GT;
&LT; / DIV&GT;
&LT; /身体GT;
&LT; / HTML&GT;
谢谢!
编辑: 我不知道是否有帮助,但如果我做了GET与此code,我得到的网页的HTML格式,如果我问这个responseText
&LT; HTML&GT;
&LT; HEAD&GT;
&LT;冠军&GT; SOAP客户端的JavaScript测试和LT; /标题&GT;
&LT;! - jQuery的/ jQueryMobile脚本 - &GT;
&LT;脚本SRC =JS / jQuery的-1.9.1.min.js&GT;&LT; / SCRIPT&GT;
&LT;脚本SRC =JS / jquery.mobile-1.3.1.min.js&GT;&LT; / SCRIPT&GT;
&LT;脚本类型=文/ JavaScript的&GT;
功能皂(){
VAR XMLHTTP =新XMLHtt prequest();
xmlhttp.open(GET,http://ws.swinggift.com/SGServices.asmx?op=GetVouchers,真正的);
//构建SOAP请求
VAR SR =
'&LT; XML版本=1.0编码=UTF-8&GT;? +
'&LT;肥皂:信封的xmlns:XSI =http://www.w3.org/2001/XMLSchema-instance的xmlns:XSD =http://www.w3.org/2001/XMLSchema的xmlns:肥皂= http://schemas.xmlsoap.org/soap/envelope/"> +
'&LT;肥皂:身体与GT; +
'&LT; GetVouchers的xmlns =http://tempuri.org/&GT; +
'&LT;登录code取代;东西&LT; /登录code基 +
'&LT; / GetVouchers&GT; +
'&LT; / SOAP:身体与GT; +
'&LT; /肥皂:信封&GT;';
xmlhttp.onreadystatechange =功能(){
如果(xmlhttp.readyState === 4和&安培; xmlhttp.status === 200){
的console.log('完成'+ xmlhttp.responseText);
$(#响应)文本($(xmlhttp.responseXML))。
}
};
//发送POST请求
xmlhttp.setRequestHeader(内容类型,为text / xml');
xmlhttp.setRequestHeader(接受,应用程序/ XML,文本/ XML,* / *);
xmlhttp.setRequestHeader(SOAPAction的,http://tempuri.org/GetVouchers);
xmlhttp.send(SR);
// 发送请求
// ...
}
&LT; / SCRIPT&GT;
&LT; /头&GT;
&LT;身体GT;
&LT;表格名称=演示行动=的方法=邮报&GT;
&LT; DIV&GT;
&LT;输入类型=按钮值=肥皂的onclick =香皂(); /&GT;
&LT; DIV ID =响应&GT;
&LT; / DIV&GT;
&LT; / DIV&GT;
&LT; /形式GT;
&LT; /身体GT;
&LT; / HTML&GT;
这是一个模拟器的问题...现在正与code以上。
I'm having a problem with trying to set up a working web service in my application I'm making using Phonegap. I need to get data from an existing web service. I found that by using a simple ajax request, this should be working. Am I not using the ajax request correctly?
The web service I'm trying to call can be found here: http://ws.swinggift.com/SGServices.asmx
EDIT: I tested it on http://wsdlbrowser.com/ and I'm getting my xml file back, how does this site work ?
I'm working in the ripple emulator so I have a cross domain proxy. I'm suspecting that my request header may be off ?
error that I'm getting: Failed to load resource: the server responded with a status of 400 (Bad Request) (10:26:26:851 | error, network) at https://rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//ws.swinggift.com/SGServices.asmx%3Fop%3DGetVouchers
(I can't make my logon code public)
my test html file:
<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>
Thanks!
EDIT: I don't know if it helps but if I do a 'GET' with the this code, I get the webpage in HTML format if I ask for the responseText
<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>
It was an emulator problem ... Working now with the code above.
这篇关于通过PhoneGap的错误阿贾克斯SOAP Web服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!