is_ajax_request does not recognized XMLHttpRequest |
10-04-2018, 02:58 AM
(This post was last modified: 10-04-2018, 06:41 AM by ciadmin. Edit Reason: Edited formatting )
Dear All,
I got issue, below php code is in controller, when i do jquery ajax requests it works but when i make a call with JS Code mentioned below it wont work. if remove (!$this->input->is_ajax_request()) check. below js code work. please anyone can suggest me what i am doing wrong or what i should do to keep (!$this->input->is_ajax_request())check, this check is important. PHP Code: if (!$this->input->is_ajax_request()) { Javascript Code: var ajax = new XMLHttpRequest();
10-04-2018, 10:02 AM
(This post was last modified: 10-04-2018, 10:04 AM by InsiteFX. Edit Reason: add lines )
Not sure what JavaScript or framework your using some do not send the HTTP_X_REQUESTED_WITH header. jQuery doe's send it.
You can try this and see what you get this is the old way that we use to do it. Code: define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); You can place the define in your ./application/config/constants.php file or were you want. You may need to send the header yourself. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
You need to manually specify the requested-with method with plain JS. jQuery and other libraries does it for it like InsiteFX said.
Code: //Send the proper header information along with the request
(10-04-2018, 10:02 AM)InsiteFX Wrote: You can try this and see what you get this is the old way that we use to do it. The above (more or less) what CI_Input does From /system/core/Input.php PHP Code: public function is_ajax_request() I think there is something in the JavaScript that is producing a non-standard XMLHttpRequest. |
Welcome Guest, Not a member yet? Register Sign In |