Telephone cross-domain does not work

$('#loginForm').submit(function() { $("#loginsubmit",this).attr("disabled","disabled"); var u = $("#loginemail", this).val(); var p = $("#loginpassword", this).val(); var postTo = 'http://www.example.com/login.php'; if(u != '' && p!= '') { //navigator.notification.alert("not empty"+u, function() {}); var apiurl = "http://www.mapyi.com/api/mapyi/client.php?"+"action=verlogin&pass="+p+"&email="+u; $.ajax({ url: apiurl, dataType: 'jsonp', jsonp: 'jsoncallback', timeout: 5000, success: function(data){ navigator.notification.alert("not empty"+data); }, error: function(msg){ navigator.notification.alert("ERROR"+msg); } }); } /* end if u and p */ //hide(); //$('#homepage').show(); return false; }); 

I added access to phonegap.xml, also aupdate manifest.xml for android. The php answer is in json:

  /* PHP CODE SErver side */ /* output in necessary format JSON */ header('Content-type: application/json'); echo json_encode(array('posts'=>$ret)); 

I don’t know what I am missing, the ERROR dialog always displays with the output ERROR [object] [object]

** DECIDED I solved it myself, I did not add header information to the php service. header ('Access-Control-Allow-Origin:'. $ _ SERVER ['HTTP_ORIGIN']); header ('Cache-Control: no-cache, must-revalidate'); Thanks CODER DECODER ENCODER for your time **

+4
source share
1 answer

You request code look great. I think you missed the server side json callback. Just return server data like this,

 echo $_GET['jsoncallback'] .json_encode(array('posts'=>$ret)); 
0
source

All Articles