3

I've got a site under development that is using lots of AJAX calls. I'm using the shortcuts - .get(), .post() and .load()

On the desktop machine, everything works just fine using any browser I've tested so far. But when I test using my iPad, all AJAX calls fail. Checking the server log reveals that they are using OPTIONS instead of GET/POST - so far that sounds like questions answered before, BUT:

a) this ONLY happens with the iPad Mobile Safari, NOT with Safari on the desktop or any other browser on the desktop b) I have tripple-checked that I am using the same domain, no subdomain, no http/https, etc.

I have no idea what's going on here, so if anyone can help?

j08691
  • 204,283
  • 31
  • 260
  • 272
Tom
  • 2,688
  • 3
  • 29
  • 53

1 Answers1

1

I had the same problem with a project in JQuery/.NET WCF where Firefox used OPTIONS verb to know what verbs are allowed (get, post, delete, put).

So i had this to my global.asax.cs file in the method "Application_BeginRequest", which is inherited by all REST Services. So when a REST service is called, it pass through that method first :

HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

if (HttpContext.Current.Request.HttpMethod == "OPTIONS") {
    HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, x-requested-with");
    HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
    HttpContext.Current.Response.End();
}

When the verb "OPTIONS" is used, the global page returns options allowed. Then the browser send the POST/DELETE/GET/PUT request.

I guess you have to do something like that. What techno do you use for your website ?

BTW, if you have a better method to get through that prob, i'ld be glad to use it too :)

Maelig
  • 2,046
  • 4
  • 24
  • 49