Chrome不正确使用AJAX到PHP脚本,用户包含指令



我在Google Chrome(12.0.742.112(中使用Ajax查询(使用JQuery lib(时遇到问题。在我的服务器端脚本(PHP(中,如果我使用"include"指令-Chrome中的FireBug说错误-

"parserror SyntaxError:意外的令牌ILLEGAL">

在其他浏览器(FF、IE、Opera(中,工作正常。来自客户端的示例代码:

$.ajax({
    type: "POST",
    data : { fun : "getconfigurations" },
    url: "test.php",
    error : function(jqXHR, textStatus, errorThrown) {
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
    },
    success: function(data) { 
        // do something
    },
    dataType: "json"
});

test.php的示例代码:

<?php
header('Content-Type: application/json; charset=utf-8');
include "test2.php";
$result = array();
$result[] = array(0 => 1, 1 => "fffffffffffffffffffffffffffff");
$result[] = array(0 => 1, 1 => "hhhhhh");
$result[] = array(0 => 1, 1 => "gggggg");
echo json_encode($result);
?>

在这个脚本中,我尝试包含一些文件(test2.php(:

<?php
function fun1()
{
return 10;
}
?>

如果我注释"include",它就可以正常工作,如果我将代码从test2.php复制到test.php,它也可以正常工作。此问题仅适用于Chrome

如果你能帮我,我会很高兴的。谢谢。

好吧,只需在浏览器中加载test.php,它就会显示输出到ajax调用的内容。输出的某些内容不是有效的JSON,chrome对此非常严格。

我怀疑在json_encode部分之前输出了一些东西

最新更新