2011-01-28 40 views
1

我們正在開發一個使用PhoneGap框架的小型聯繫商店應用程序。我們有一個web服務來執行創建,更新,閱讀和刪除聯繫人的操作。我們使用下面的代碼來創建SOAP請求來創建聯繫人。我們正在使用jQuery和jQuery手機http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.js。以下代碼與iPhone模擬器和iPhone一起工作。但是我們甚至沒有在Android和Android模擬器上獲得響應。我們非常感謝您的幫助。PhoneGap使用jQuery的Android Web服務響應不會到來

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>[email protected]</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"); 
    } 
}); 
+0

在我看來,它應該工作。如果您運行`adb logcat`來查看設備/仿真器上的日誌,您是否看到任何錯誤?試着做`adb logcat | grep「Web」`只獲得與瀏覽器/ PhoneGap相關的輸出。 – 2011-01-29 20:22:49

回答

0

我也有同樣的問題。 當我試圖在eclipse上運行index.html時,一切正常。 但是,當試圖在模擬器上運行時,沒有響應數據。 我發現即使響應數據的長度爲零也是如此。

如果有人可以發佈解決方案或者phonegap如何運行一個接受soap xml請求並在xml中給出響應的Web服務的小示例,那將會很棒。

0

我試過運行logcat,但沒有找到任何「Web」字,當點擊運行web服務的按鈕時。

0

嘗試使用settings.dataType =「xml」(而不是「text/xml」)。

「text/xml」不是$ .ajax調用的有效數據類型,因此智能猜測可能在您的iphone中運行,而不是在您的android sim中運行。