You must use json data to respond to the client. For example: In a PHP file
<?php
$data = '<table></table>';
if($is_timeout && $is_ajax_request) {
echo json_encode(array('timeout'=>1));
die();
}else{
echo json_encode(array('data'=>$data));
die();
}
And in your javascript postyou can edit below:
$.post('your_url_to_php_file',{data:data_to_post}, function(resp){
var data = jQuery.parseJSON(resp);
if(data.timeout) {
alert("timeout");
return;
}else{
$("#your_div").html(data.data);
}
})
source
share