Phonegap Jquery移动跨域ajax请求不工作

问题描述:

我想从我的phonegap应用程序的ajax请求到一个服务器端代码写在php这是在我的本地主机。我试图使用jsonp请求。这是我的代码

I am trying to make a ajax request from my phonegap app to a serverside code written in php which is on my localhost. I am trying to use the jsonp request. This is my code

        $.ajax({
            url: 'http://localhost/score-tracker/get-groups.php',
            type: 'GET',
            contentType: "application/json",
            async: true,
            dataType: 'jsonp',
            crossDomain: true,
            success: function(resp){},
            error: function(err) {}
        });

但是控件不会返回错误或成功回调。我已启用此功能:

But the control does not return either in error or success callbacks. I even have this enabled :

$.support.cors = true;
$.mobile.allowCrossDomainPages = true;

当我在chrome控制台中检查请求时,我发现状态为failed pending

WHen i check the request in chrome console, I find the status as "failed" and type as "pending"

这是我的服务器端代码:

This is my server side code :

require_once('AddGroup.php');
header('content-type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
$a = json_encode(array('a' => 1, 'b' => 2));
echo $_REQUEST['callback'].'('.$a.')';

请帮助我。我真的坚持这一点。

Please help me. I am really stuck with this.

谢谢

只要张贴答案,如果任何人发现有用的话

I got the problem solved. Just posting the answer if any one finds it helpful

$.ajax({
        url: 'http://<ip>/score-tracker/get-groups.php',
        type: 'GET',
        contentType: "application/json",
        async: true,
        dataType: 'jsonp',
        crossDomain: true,
        success: function(resp){},
        error: function(err) {}
    });

在apache的http.d conf文件中,我有权限拒绝www directoy得到禁止的错误。我允许访问该目录,问题解决了。

And in the http.d conf file of apache I had permission denied to the www directoy for which I was getting the forbidden error. I allowed access to that directory and the problem was solved.