【问题标题】:How to use Magento API Soap Web services in PhoneGap如何在 PhoneGap 中使用 Magento API Soap Web 服务
【发布时间】:2013-03-01 14:57:03
【问题描述】:

我正在使用 PhoneGap 进行 iOS 开发。我正在尝试在 PhoneGap 中致电 Magento API With the SOAP Web services。我的场景是我想将用户名和 apikey 发送到 Web 服务。由于它是在 jQuery-Ajax 和 javascript 的帮助下基于客户端的,因此我尝试将数据发送到 Web 服务但失败了。

当我尝试使用 Jquery-Ajax 时,我收到一个 XML 解析错误,将“0”作为错误消息(跨域问题)。在 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 服务?

【问题讨论】:

    标签: javascript magento jquery cordova


    【解决方案1】:

    我觉得你不用回避jquery的跨域问题。

    1.一个简单的 'jsonp' 将帮助您解决您的问题。 2.您可以在服务器端修改响应头。 请参考下面我的c#代码:

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

    【讨论】:

    • 我已经尝试使用* 代码,但我的问题仍然存在。 jsonp会在phonegap中支持吗?
    • Jsonp 支持 jquery。我用它来解决跨域问题很多次了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多