??yy 2015-02-20 13:17 采纳率: 0%
浏览 78

科尔多瓦阿贾克斯(Cordova Ajax)错误要求

I've got a simple server app running on Heroku that I'm making ajax calls to from a Cordova app. I've setup CORS on the server app and I can call the server from my browser without any problems. However, when I call the server using the exact same code from within Cordova I get a Bad Request error!!

$.ajax({
    url: 'http://{myserver}/{function}',
    type: 'GET',
    data: { mydata... },
    success: function(resp){ alert("success"); },
    error: function(err) { alert(err.statusText); }
});

I've tried adding crossDomain: true and dataType: 'jsonp', it makes no difference. I've also checked that all domains are whitelisted in Cordova <access origin="*" />

Why can't I access the server from Cordova when I can access it from my browser?

  • 写回答

1条回答 默认 最新

  • weixin_33725722 2015-02-20 13:37
    关注

    Figured it out! The reason was that I has a misspelling in data: { ... } so one of the parameters was missing.

    评论

报告相同问题?