简体   繁体   English

Ajax 无法在使用 phonegap 的 android 手机中工作

[英]Ajax is not working in android phone using phonegap

"it always alert failure but in case of browser its working fine nor its send data to ajax url " “它总是警告失败,但在浏览器工作正常的情况下,它也不会将数据发送到 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;
            }

    });

try like this :试试这样:

  $.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;
                            }
                        });

You have to whitelist the URL host (ie http://182.18.164.87/ ) in your config.xml, otherwise it will be blocked for security reason:您必须在 config.xml 中将 URL 主机(即http://182.18.164.87/ )列入白名单,否则出于安全原因它将被阻止:

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

You will need the whitelist plugin too.您也将需要白名单插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM