0

我有一个 hello.php 文件,其中包含一些基本的 html。我正在使用 ajax 从 another.php 文件中检索数据。jQuery 脚本将数据发布到 another.php 并将回调数据放入 div。

问题是来自 .post 的回调数据包含 hello.php 中的所有内容以及实际的回调数据(请查看下方)。我已经从实际文件中缩短了文件(例如包含 DB 连接),但无论我使用实际文件还是这些存根,效果都是一样的。这以前工作得很好,但是当我为该站点创建登录操作时被破坏了。仅包含不同类的对象,这些对象不适用于发布,并且没有引用包含 hello.php 文件。

有没有人遇到过类似的问题?

你好.php

<html>
    <head>scripts etc..</head>
    <body>
        <h1>Hello</h1>
        <button id="dataButton" value="GetData">Get Data</button>
        <div id="cb">Callback data here</div>
    </body>
</html>

另一个.php

<?php 
    echo "world!";
?>

jQuery 脚本

<script>
function getWorld() {
    $.post("another.php", function(data) {
        $("#cb").html(data);

        // alert(data); this also contains all of the data in This page 

    });
}
</script>

js函数

<script>
$(document).ready(function() {
    $("#dataButton").click(function() {
        getWorld();
    });
});
</script>

这将输出以下 html 页面源代码:

<html>
    <head>scripts etc..</head>
    <body>
        <h1>Hello</h1>
        <button id="dataButton" value="GetData">Get Data</button>
        <div id="cb">
<html>
    <head>scripts etc..</head>
    <body>
        <h1>Hello</h1>
        <button id="dataButton" value="GetData">Get Data</button>
        <div id="cb">Callback data here</div>
    </body>
</html>

<script>
$(document).ready(function() {
    $("#dataButton").click(function() {
        getWorld();
    });
});
</script>

<script>
function getWorld() {
    $.post("another.php", function(data) {
        $("#cb").html(data);

        // alert(data); this also contains all of the data in This page 

    });
}
</script>

world! // <-- 这从服务器返回。

<script>
$(document).ready(function() {
    $("#dataButton").click(function() {
        getWorld();
    });
});
</script>

<script>
function getWorld() {
    $.post("another.php", function(data) {
        $("#cb").html(data);

        // alert(data); this also contains all of the data in This page 

    });
}
</script>
4

0 回答 0