$.ajax get data from server, the status is 200
, but the response is empty. I using the same method to send my ajax request, some is normal, but there is some requests
/customer/api/show/r:571?nav=push
/customer/api/show/r:571?nav=push&status=sended
they don't have any response from server. The console always say: 'This request has no response data available'. But the requests like these are fine:
/customer/api/show/r:311?nav=report
/customer/api/show/r:30?nav=dashboard
... ...
Why?
Here is the details :
request ----------------------
var request = $.ajax({
url: 'customer/api/show/r:' + Math.round(Math.random() * 1000),
data: params,
dataType: 'json',
success: function (res) {
/* do something, like: update the dom with the res.html */
},
error: function() {
}
});
response ----------------------
General:
Request URL:http://test.local/api/show/r:31?nav=push
Request Method:GET
Status Code:200 OK
Remote Address:127.0.0.1:80
Response Headers:
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Tue, 17 Jan 2017 08:58:50 GMT
Server:nginx/1.10.0
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:PHP/5.5.36
......
the details (wireshark) about the request
Here is my server-side codes (PHP):
......
ob_start();
$this->render("customer/static/" . $nav . ".php"); /* html with php */
$result->html = ob_get_clean();
echo json_encode($result);
......
The "$this->render" methods:
public function render($filename, $output_content=TRUE) {
global $C, $D;
$filename = $C->INCPATH . '../html/' . $filename;
if ($output_content) {
require($filename);
return TRUE;
} else {
ob_start();
require($filename);
$cnt = ob_get_contents();
ob_end_clean();
return $cnt;
}
}
PS:
if ($nav !== 'push') {
ob_start();
$this->render('customer/static/' . $nav . '.php');
$result->html = ob_get_clean();
} else {
$result->html = 'testing';
}
The response is normal...