我正在通过 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/