【问题标题】:PhoneGap Android Web Service response using jQuery is NOT coming没有使用 jQuery 的 PhoneGap Android Web 服务响应
【发布时间】: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


【解决方案1】:

我也遇到了同样的问题。 当我尝试在 Eclipse 上运行 index.html 时,一切正常。 但是尝试在模拟器上运行时,没有响应数据。 我发现连响应数据的长度都是零。

如果有人可以发布解决方案或一个关于 phonegap 如何运行 Web 服务的小示例,该服务接受一个肥皂 xml 请求并以 xml 形式给出响应,那就太好了。

【讨论】:

    【解决方案2】:

    我尝试运行 logcat,但是当单击运行 Web 服务的按钮时,我没有找到任何“Web”字样。

    【讨论】:

      【解决方案3】:

      尝试使用 settings.dataType = "xml"(而不是 "text/xml")。

      "text/xml" 不是 $.ajax 调用的有效数据类型,因此智能猜测可能已经在您的 iphone 中运行,而不是在您的 android sim 中。

      【讨论】:

        猜你喜欢
        • 2015-03-28
        • 1970-01-01
        • 2014-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多