我想以 JSON 格式发送数据并获得响应以实现快速响应。所以我正在使用 AJAX。为什么我得到
"内容类型 text/html; charset=UTF-8 "
为什么得不到
内容类型应用程序/json
控制器
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);
}
});
标题
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