I want to send data and get response as JSON for fast response. So i am using AJAX. Why i am getting
"Content-Type text/html; charset=UTF-8"
Why not getting
Content-Type application/json
Controller
public function testingMethod() {
$this->autoRender = false;
$urlVal = $_POST['urlVal'];
$dataBack = json_encode($urlVal);
if ($this->RequestHandler->isAjax()) {
return $dataBack;
}
}
jQuery
$.ajax({
type: "POST",
url: pathname+"Frontends/testingMethod",
data: 'urlVal=' + urlVal,
dataType: 'json',
success: function (result) {
console.log(result);
alert(result);
}
});
Header
Response Headers
Connection Keep-Alive
Content-Length 2382
Content-Type text/html; charset=UTF-8 //why here not getting application/json
Date Wed, 14 Aug 2013 10:17:38 GMT
Keep-Alive timeout=5, max=94
Server Apache/2.2.22 (Win32) PHP/5.4.3
X-Powered-By PHP/5.4.3
Content-Typeheader, that’s why. - Martin Bean