Garrett
Garrett

Reputation: 11725

Why isn't my mobile site able to send AJAX requests?

The first action available in my mobile app is a login. The form calls the javascript:

$.post('http://www.website.com/m/users/login', ...

I use a catch-all ajax error:

$(document).ajaxError(ajaxError);
function ajaxError() {
    hideLoader();
    enableForm( $('form:visible') );
    alert('Uh oh! An error occurred. Please make sure you have an internet connection and try again.');
}

And that alert is all I get when I try to log in.

Even though it isn't cross domain (the mobile site is at mobile.website.com), I have tried:

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

But it still isn't working. At this point I'm out of ideas, so I thought I'd see if anyone knew of any other possible roadblocks for JQM ajax requests.

Thanks :)

Upvotes: 0

Views: 117

Answers (3)

Vinayak Bevinakatti
Vinayak Bevinakatti

Reputation: 40503

Using YQL will also let you do Cross domain AJAX calls

Build your URL query using YQL Console and use the YQL query directly in your code and you will get the response reliably

Upvotes: 0

Dewfy
Dewfy

Reputation: 23624

Try review technique called JSONP this way you can perform cross-site invocation

Upvotes: 1

Kevin B
Kevin B

Reputation: 95022

You are performing a cross-domain request,www.website.com is not the same domain as mobile.website.com. You either need to expose the methods on the mobile.website.com domain, make www.website.com support CORS, or provide some kind of proxy between the two.

Upvotes: 1

Related Questions