2013-03-01 35 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