Welcome Guest, Not a member yet? Register   Sign In
is_ajax_request does not recognized XMLHttpRequest
#1

(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()) {
 
redirect('backend');
 
 exit();
}else{
 
// Continue to process


Javascript
Code:
var ajax = new XMLHttpRequest();
           ajax.open("POST", ajaxUrl, true);
           ajax.onreadystatechange = function () {
               if (this.readyState == 4) {
                   if (this.status == 200) {
                       console.log(this.response);
                       console.log(typeof this.response); // should be a blob
                       var blob = new Blob([this.response], {type: "application/octet-stream"});

                       //saveAs(blob, file_name);
                   } else if (this.responseText != "") {
                       console.log(this.responseText);
                   }
               } else if (this.readyState == 2) {
                   if (this.status == 200) {
                       this.responseType = "blob";
                   } else {
                       this.responseType = "text";
                   }
               }
           };
           ajax.send(null);
Reply


Messages In This Thread
is_ajax_request does not recognized XMLHttpRequest - by tecthon - 10-04-2018, 02:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB