Hello, I am trying to make Ajax requisitions and when I try check $this->request->isAjax() == true is always returning false but if I print inside the condition of isPost is working. my view: item/index.html.
<script type="text/javascript">
var http;
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
http.open('POST', 'https://127.0.0.1/item/search', true);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send('user=test');
</script>
ItemController.php
public function searchAction(){
$this->view->disable();
$request = new Request(); // I make this becaus I was triying $request->isAjax()
$response = new Response();
$response->setHeader("Content-type", "application/json;charset=utf-8");
if ($this->request->isPost() == true) {
if ($this->request->isAjax() == true) {
//here is print nothing
$user = $this->request->getPost('user');
$sucess = array ('this' => $user);
echo json_encode($sucess);
}
//here prints
}
}