微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决Apache Web服务器为Json Response发送<html>标记

我有一个简单的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();
    ?>

我正在使用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))”方法。当我删除它时,我可以看到错误已得到解决。谢谢大家的评论!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。