10-04-2018, 02:58 AM
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.
Javascript
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);