Apache Web 服务器为 <html> Json 响应发送标记



我有一个类似的简单Ajax调用

$('#getOrgs').on('click', function() { 
var form_data=new FormData(document.getElementsByName('f_xmlupdates')[0]);      
$.ajax({
url: 'ajax/getOrgs.php', 
dataType: 'json', 
contentType: false,
processData: false,
data: form_data,                       
type: 'post',
success: function(php_script_response){
$('#atscale_org').empty();
jQuery.each( php_script_response, function( i, val ) {
$('#atscale_org').append($('<option></option>').val(val[0]).html(val[1]));
});
$('#getOrgs').css('background','dimgrey');
},
error: function ( error ) {
console.log("Something Wrong with GetOrgs..."+JSON.stringify(error));
}
});
});

Php Side-getOrgs.Php

<?php 
header('Content-Type: application/json; charset=utf-8');
include('../utils/utils.php');
$organization = get_orgs_from_pg( $_POST["atscale_server"] );
echo json_encode($organization,TRUE);
exit();
?>

我使用的是ApacheWebServer2.4.29。上面的代码填充了一个选择框。这在一天中的大部分时间都很好,有时(几天一次(Ajax调用进入Error块而不是Success块。我看到ServerState:4错误消息。我看到PHP的响应有以开头的标签

<!DOCTYPE HTML>
<html>
<head>
</head> 
<body>
{json Response}
</body>
</html>

一旦我重新启动ApacheWeb服务器,这个问题就会消失。有人能给我一些提示吗?是哪个进程在添加HTML标记?为什么会突然发生?

看起来问题出在"htmlentities($row[2]、ENT_XHTML((";方法。当我删除它时,我可以看到错误正在得到解决。谢谢大家的评论!!

最新更新