【问题标题】:Ajax is not working in android phone using phonegapAjax 在使用 phonegap 的 android 手机中不起作用
【发布时间】:2017-10-26 20:38:22
【问题描述】:

“它总是提醒失败,但如果浏览器工作正常,也不会将数据发送到 ajax url”

jQuery.ajax({
          url:'http://182.18.164.87/jd/action.php?action=register',
          crossDomain: true,
          type: 'POST',  
          data: data,
          contentType: "application/json",  
          dataType: 'jsonp',  
          jsonp: 'jsoncallback',
          timeout: 5000,
          success: function(data,status){

                    alert('success');
                    localStorage.clear();



               return true;
            },
            error: function(){
                alert('failure')
            return false;
            }

    });

【问题讨论】:

    标签: android jquery phonegap


    【解决方案1】:

    试试这样:

      $.ajax({
                             type: "POST",
                             url: "http://182.18.164.87/jd/action.php",
                             data: {"data":val},
                             cache: false,
                             async:false,
                             success: function(data){ 
    
                                 var data = JSON.parse(data);   
                                 alert('success');
                                  localStorage.clear();
    
                                },
                                error: function(){
                                     alert('failure')
                                   return false;
                                }
                            });
    

    【讨论】:

      【解决方案2】:

      您必须在 config.xml 中将 URL 主机(即http://182.18.164.87/)列入白名单,否则出于安全原因它将被阻止:

      <access origin="http://182.18.164.87" />
      

      你也需要白名单插件。

      【讨论】:

      • 感谢您在 config.xml 中的 中使用此行。
      猜你喜欢
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      • 2015-10-02
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-17
      相关资源
      最近更新 更多