Welcome Guest, Not a member yet? Register   Sign In
trouble with is_ajax_request()
#4

(This post was last modified: 01-26-2019, 12:44 AM by richb201.)

OK. I got it fixed. Here is what I have found for the next person who has this problem. In order to send a message from a browser to CI on a server via XMLHTTP, you need to set

       xhr.setRequestHeader("X-REQUESTED-WITH",'xmlhttprequest'); 

Otherwise $this->input->is_ajax_request() will not recognize the request as ajax. But if you include X-Requested-with in your header, then your browser will send the message as OPTIONS which means it first sends a preflight request. You server code need to ignore that pre-flight which is easy since $this->input->is_ajax_request() will not return a true for a preflight. I also added the following to the .htaccess

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Accept,Authorization,Content-Type,Origin,X-Requested-With"
Header set Access-Control-Allow-Methods "GET, POST, PATCH, PUT, DELETE, OPTION"
Header set Access-Control-Max-Age: 86400

The bottom line is that although I didn't want a preflight I was forced to deal with it because of the X-REQUESTED-WITH requirement of is_ajax_request().
proof that an old dog can learn new tricks
Reply


Messages In This Thread
trouble with is_ajax_request() - by richb201 - 01-24-2019, 11:07 AM
RE: trouble with is_ajax_request() - by InsiteFX - 01-25-2019, 04:28 AM
RE: trouble with is_ajax_request() - by richb201 - 01-25-2019, 06:56 AM
RE: trouble with is_ajax_request() - by richb201 - 01-26-2019, 12:42 AM
RE: trouble with is_ajax_request() - by InsiteFX - 01-26-2019, 06:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB