jQuery를PHP가 json 데이터를 호출 스크립트로 보내고 flush()와 같은 처리를 재개 할 수 있습니까?
var result='';
jQuery.ajax
({
contentType: "application/json; charset=utf-8",
dataType: "json",
url: <?php echo '"' .plugins_url('/test.php', __FILE__); ?>?Query="+ jQuery('#test').val(),
success: function(data)
{
//process results
},
error: function(jqXHR, textStatus, errorThrown){
console.log(arguments);
alert('HTTP Error: '+errorThrown+' | Error Message: '+textStatus);
return;
}
});
test.php
$file = $rootPath.'wp-content/uploads/test/'.$query.".txt";
if (file_exists($seoCacheFile) && is_readable($seoCacheFile))
{
$retarr = file_get_contents($file);
if($retarr !=="")
{
print_r($retarr);die;
}
}
if(count($ret)){
$retarr = json_encode(array('response' => array('test' => array('Results'=>$ret))));
print_r($retarr);
flush();
//PROBLEM IS HERE
//If an error occurs here, the json is mangled, flush() does not help. Can I send the json and deal with PHP errors separately?
/* if (!is_dir($rootPath.'wp-content/uploads/test/')){mkdir($rootPath.'wp-content/uploads/test/');}
$seoCacheFile = fopen($rootPath.'wp-content/uploads/test/'.$query.".txt",'w');
fwrite($File, $retarr);fclose($File);
*/
}
아니면 내가 그것으로 JSON을 전달하는 PHP에서 쓰기 작업을 이동하고 두 번째 Ajax 호출을 작성해야합니까?
맹 글링 된 출력은 어떻게 생겼습니까? 나머지 코드가 아무런 결과도 출력하지 않는 한 (즉, 다른 오류는 표시하지 않거나 파일에 쓰는 일을 먼저하고 JSON에 오류가 있으면 문제를 보내면 모두 한 요청을 처리 할 수 있어야합니다. 발생합니다). –
출력은 완벽한 json 데이터이며, 호출 스크립트에서 모든 것을 throw하는 PHP 오류 메시지로 끝납니다. – RegEdit
글쎄, 표시 오류를 사용하지 않도록 설정할 수 있지만 출력을 망가 뜨리지 않도록 오류를 수정해야합니다. –