javascript - jQuery AJAX 函数返回奇怪的输出

标签 javascript php jquery ajax

我正在通过 jQuery 对 php 文件进行 AJAX 请求,并且得到了一些奇怪的输出。

main.php:

<!DOCTYPE html>

<head>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>

<body>

    <?php
        include('main.html');
    ?>

    <script type='text/javascript'>

        $('#startButton').click(function() {

            $.ajax({
                method: "POST",
                url: "test.php",
            }).done(function(data) {
                alert(data);
            });

        });


    </script>

</body>

test.php:

<?php

    echo 'Hello';

?>

我的程序不是在单击按钮时提醒“Hello”,而是提醒 main.php 的 html。知道发生了什么吗?

最佳答案

弄清楚了 - 我正在使用 GoogleAppEngine,并且我的 app.yami 文件未配置为将请求定向到 test.php,因为它默认将所有请求发送到 main.php,因此返回 html。

抱歉没有说明我正在使用 GAE - 我认为这不相关。

感谢@Dagon 指出这是一个重定向错误,使我得到了正确的答案。

关于javascript - jQuery AJAX 函数返回奇怪的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30282303/

相关文章:

javascript - 在 Javascript 中声明一个空的二维数组?

javascript - 如何在浏览器中使用自动渲染(LaTeX 0.9.0-alpha)?

javascript - JQuery 是否有类似于 Ruby 的 sort_by 函数

javascript - 吴 map : Why are my markers (ng-repeat directive) passing through multiple parameters?

php - 如何从双引号中提取字符串?

javascript - 读取 php/js 中的 JSON 响应对象

javascript - 如何向模态框(灯箱)Typo3 扩展添加关闭按钮?

c# - 如何通过 Jquery Ajax Get 将对象传递给 MVC Controller

php - 如何使用 JQuery、PHP 和 MySQL 单击链接时显示图像?

javascript - 向 Google 日历 API 发出 GET 请求