gpt4 book ai didi

php - AJAX 没有响应

转载 作者:行者123 更新时间:2023-11-30 13:22:20 25 4
gpt4 key购买 nike

所以我试图从我的 php 文件中提醒我的“你好”,它非常简单,但由于某种原因它不起作用。

JS

    function dynamic()
{
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
window.alert(xmlhttp.responseText);
}
}

xmlhttp.open("POST", "hello.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}

dynamic();

PHP

<?php 
echo "Hello";
?>

HTML

<html>
<head>
<title>Hello</title>
<script src="dynamic.js"></script>
</head>
<body>

test

</body>
</html>

我无法让警告框提醒我“你好”。它应该直接来自 responseText。

最佳答案

您没有调用send 方法。它发送请求 MDN

xmlhttp.send();

如果您想将任何数据放入 POST 中,请将其作为 urlencoded 形式放入发送方法参数中。

xmlhttp.send("foo=bar&hello=world");

关于php - AJAX 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9799096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com