AJAX返回随机哈希而不是文本

时间:2015-04-13 20:46:18

标签: javascript jquery ajax

我正在处理实时通知脚本。 我已设法将请求发送到外部文件,但脚本返回随机哈希而不是纯文本...

这是我应该从test.php获取数据的函数

<script>
$(document).ready(function () {

    function load() {
        $.ajax({ //create an ajax request to load_page.php
            type: "GET",
            url: "/test.php",
            dataType: "html", //expect html to be returned                
            success: function (response) {
                $("#responsecontainer").append(response);
                setTimeout(load, 5000)
            }
        });
    }

    load(); //if you don't want the click
   // $("#display").click(load); //if you want to start the display on click
});
</script>

它应附加到结果中。

这是test.php的来源

    <!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Headerview</title>
</head>

<body>
<?php
    $p = "<p>test</p>";
    echo $p;
    ?>
</body>
</html>

这就是我得到的...... INGN ^ PtJRo(HI * I1HVb&安培; pB0wJs(B)9rID * 6OEyh6cngWD + 93Zr $ zYU

1 个答案:

答案 0 :(得分:0)

文件路径是问题所在。我没有指定确切的文件路径。 谢谢