开发者

PhoneGap jQuery JSONP returned error

I got problem with parsing data. I send ajax request and as I can see, I get data back. But insted of going to success function, script runs error function, so something must be wrong.

$.ajax("http://www.test.com/something/request", {
    crossDomain:true, 
    dataType: "jsonp",
    success:function(data){
                alert("Working");
        data = evalJSON(data);
    }, error: function() { ale开发者_StackOverflow社区rt("Error"); }
});

Json data:

[1,{"Id":"1","Url":"my-url","Name":"Name"}]


try this

$.getJSON("http://www.test.com/something/request?callback=?", {
    success:function(data){
                alert("Working");
        data = evalJSON(data);
    }, error: function() { alert("Error"); }
});

And return the JSON data with the callback function wrapped around it. In PHP that would be like this:

echo $_GET['callback'] . '(' . '[1,{"Id":"1","Url":"my-url","Name":"Name"}]' . ')';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜