Welcome Guest, Not a member yet? Register   Sign In
is_ajax_request() doesn't work from mobile apps

I'm not sure if this is expected or if there's an alternative, but is_ajax_request() doesn't work from when handling an ajax request from a mobile app.

I'm developing an app using Phonegap, with my existing CI3 site as the back end. I have several methods setup to return data as JSON (these are also used in the normal web-based version of the app). I prevent direct access to these using an is_ajax_request() check, but this is failing when called from my mobile app (returns false).

Anyone know if there is a workaround or fix for this?


(This post was last modified: 04-07-2015, 05:05 AM by Narf.)

is_ajax_request() depends on a non-standard HTTP request header named 'X-Requested-With', that for AJAX requests should have the value of 'XMLHTTPRequest' (case-insensitive). It is the client that sends or doesn't sent that header, and as far as any server is concerned - an HTTP request is an HTTP request, it doesn't know who, what or how has sent it.

If the client (in your case, the mobile device) doesn't say that it is sending an AJAX request, the server has no way of knowing that. Therefore, if anything can be "fixed" it's the client.

Now the ajax is updated and we can post it from the mobile apps.

Theme © iAndrew 2016 - Forum software by © MyBB