问题描述
$('#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
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();
?>
我正在使用Apache WebServer 2.4.29。上面的代码填充了一个选择框。这在一天中的大部分时间都可以正常工作,有时(几天后),Ajax调用会进入Error块而不是Success块。我看到ServerState:4错误消息。而且我看到来自PHP的响应具有以'
开头的标签<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
{json Response}
</body>
</html>
重新启动Apache Web服务器后,问题消失了。有人可以给我任何指针,哪个进程正在添加HTML标记?为什么会突然发生?
解决方法
看起来问题出在我的php函数中,原因是“ htmlentities($ row [2],ENT_XHTML))”方法。当我删除它时,我可以看到错误已得到解决。谢谢大家的评论!