phonegap Android跨域无法正常工作

时间:2012-06-22 07:07:30

标签: android cordova cross-domain-proxy

$('#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;
     });

我已经在phonegap.xml中添加了访问权限,也为Android安装了aupdate manifest.xml。 php响应在json中:

               /* PHP CODE SErver side */


/* output in necessary format JSON */

header('Content-type: application/json');
echo json_encode(array('posts'=>$ret));

我不知道我错过了什么,它总是显示ERROR对话框输出ERROR [object] [object]

**分辨 我自己解决了,我没有在php服务中添加头信息。 header('Access-Control-Allow-Origin:'。$ _ SERVER ['HTTP_ORIGIN']); header('Cache-Control:no-cache,must-revalidate'); 感谢CODER DECODER ENCODER为您的时间**

1 个答案:

答案 0 :(得分:0)

您的请求代码看起来很完美。我想你错过了服务器端的json回调。只需返回这样的服务器数据,

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