2013-03-01 80 views
2

我正在使用PhoneGap進行iOS開發。我正嘗試在PhoneGap中撥打Magento API With the SOAP Web services。我的場景是我想發送用戶名和API到Web服務。由於它的客戶端基於jQuery-Ajax和JavaScript的幫助,我嘗試將數據發送到Web服務,但失敗了。如何在PhoneGap中使用Magento API Soap Web服務

當我嘗試使用Jquery-Ajax時,我得到了一個XML解析錯誤狀態'0'作爲錯誤消息(Cros Domain問題)。在Javascript中我能得到正確的響應,但不知道如何將用戶名和apikey發送到Web服務,下面是腳本代碼,我用,

<script type="text/javascript"> 
    // Create the XHR object. 

    function createCORSRequest(method, url) { 
    var xhr = new XMLHttpRequest(); 
    if ("withCredentials" in xhr) { 
     // XHR for Chrome/Firefox/Opera/Safari. 
     xhr.open(method, url, true); 
    } else if (typeof XDomainRequest != "undefined") { 
     // XDomainRequest for IE. 
     xhr = new XDomainRequest(); 
     xhr.open(method, url); 
     } else { 
    // CORS not supported. 
     xhr = null; 
    }return xhr; 

// Make the actual CORS request. 

function makeCorsRequest() { 
    // All HTML5 Rocks properties support CORS. 
    var url = 'my WSDL link for magento api'; 
    var xhr = createCORSRequest('GET', url); 
    if (!xhr) { 
     alert('CORS not supported'); 
    return;} 
    // Response handlers. 
    xhr.onload = function() { 
    var text = xhr.responseText; 
     alert('Response from CORS request to ' + url); 
    }; 
    xhr.onerror = function() { 
     alert('Woops, there was an error making the request.'); 
    }; 
    xhr.send(); 
} 
</script> 

在這裏,我不知道如何發送的用戶名和apikey這個Soap Web服務。

任何人都可以給我建議

  • 如何發送用戶名和apikey到SOAP Web服務?
  • 是否有任何其他方式使用客戶端編程發送數據到SOAP Web服務?

回答

0

我認爲你沒有必要避免jquery的跨域問題。

1.一個簡單的'jsonp'將幫助你解決你的問題。 2.您可以修改服務器端的響應頭部。 請參考我的c#代碼如下:

HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*"); 
+0

我試過'''代碼已經仍然存在我的問題。 jsonp會支持phonegap嗎? – Sabarish 2013-03-01 07:00:33

+0

Jsonp支持jquery。我曾用它來解決跨時期的問題。 – 2013-03-01 12:28:02