Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Apache Web服务器为Json响应发送标记_Javascript_Php_Ajax_Apache_Webserver - Fatal编程技术网

Javascript Apache Web服务器为Json响应发送标记

Javascript Apache Web服务器为Json响应发送标记,javascript,php,ajax,apache,webserver,Javascript,Php,Ajax,Apache,Webserver,我有一个简单的Ajax调用,比如 $('#getOrgs').on('click', function() { var form_data=new FormData(document.getElementsByName('f_xmlupdates')[0]); $.ajax({ url: 'ajax/getOrgs.php', dataType: '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端-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();
    ?>
我使用的是ApacheWebServer 2.4.29。上面的代码填充了一个选择框。这在一天中的大部分时间都可以正常工作,有时几天内Ajax调用会进入错误块而不是成功块。我看到ServerState:4错误消息。我看到PHP的响应以

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

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

看起来问题出在我的php函数中的htmlentities$row[2]方法上。当我删除它时,我可以看到错误正在得到解决。谢谢大家的评论

您刚才说过,问题的原因是,如果服务器端出现错误,那么您将无法获取xml。。。。在这种情况下,您可以像解析纯xml一样解析该结果。也许在一个错误中,查找body标记来破译那里的html/xml?也不知道这个get_orgs_从_pg得到什么。它就像一个黑匣子。无法调试。添加HTML标记的过程是提供回退的服务器,默认内容是配置为在无法识别请求时发回的。@GetSet函数get\u orgs\u from\u pg只从postgres返回几行,而$row=pg\u fetch\u row$result{array_push$resp,array htmlentities$row[0],ENT_XHTML,htmlenties$row[1],ENT_XHTML,htmlenties$row[2],ENT_XHTML;}返回$resp;是htmlentities,在json响应上添加这些标记吗?我将删除htmlentities并尝试。当我再次遇到错误时,我将尝试删除htmlentities。现在,ajax正在正确地接收json响应。