【发布时间】:2011-01-28 14:38:25
【问题描述】:
我们正在使用 PhoneGap 框架开发一个小型联系人存储应用程序。我们有一个网络服务来执行创建、更新、读取和删除联系人的操作。我们正在使用以下代码发出 SOAP 请求以创建联系人。我们正在使用 jQuery 和 jquery mobile http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.js。以下代码适用于 iPhone 模拟器和 iPhone。但我们甚至没有在 Android 和 Android 模拟器上得到响应。我们非常感谢您的帮助。
var settings = {requestType:"soap1.1",
error:function(XMLHttpRequest, textStatus, errorThrown){
throw XMLHttpRequest.responseText;
}};
var oBuffer = new Array();
settings.requestType = "soap1.1";
settings.methodType = "POST";
settings.contentType = "text/xml";
settings.url = "http://example.com/checkdatpriceservice.asmx";
settings.dataType = "text/xml";
settings.nameSpace = "http://tempuri.org/";
settings.methodName = "VerifyUser";
oBuffer.push('<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/">');
oBuffer.push("<soap:Body>");
oBuffer.push('<VerifyUser xmlns="http://tempuri.org/">');
oBuffer.push('<email_id>abcd@example.com</email_id>');
oBuffer.push('<password>user123</password>');
oBuffer.push("</VerifyUser>");
oBuffer.push("</soap:Body>");
oBuffer.push("</soap:Envelope>");
settings.requestData = oBuffer.join("");
alert("requestData:" + settings.requestData);
$.ajax({
type: settings.methodType,
cache: false,
url: settings.url,
data: settings.requestData,
contentType: settings.contentType,
dataType: settings.dataType,
error: function(status){ alert("An error occurred in processing your request");},
success: function(data, testStatus){
alert('data = ' + data);
$('#testp').html(data);
},
beforeSend: function(XMLHttpRequest){
if (settings.requestType == "soap1.1" || settings.requestType== "soap1.2")
XMLHttpRequest.setRequestHeader("SOAPAction",settings.nameSpace + settings.methodName);
XMLHttpRequest.setRequestHeader("Content-Length",settings.requestData.length);
XMLHttpRequest.setRequestHeader("Connection", "close");
}
});
【问题讨论】:
-
在我看来它应该可以工作。如果您运行
adb logcat查看设备/模拟器上的日志,您是否看到任何错误?尝试使用adb logcat | grep "Web"仅获取与浏览器/PhoneGap 相关的输出。 -
我这里也有类似的问题:stackoverflow.com/questions/10176985/…你找到解决方案了吗?
标签: android web-services cordova