php - responseText 没有显示任何内容

标签 php javascript ajax httpresponse

我正在尝试使用 Ajax,并使用以下代码。

var r = new XMLHttpRequest();
r.open("POST", "pythonTesting.php", true);
r.onreadystatechange = function () {
    if (r.readyState === 4 && r.status === 200) {
        alert("Success: " + r.responseText);
    }
};
r.send("text=yellow");

成功,但警报未显示实际的responseText

pythonTesting.php(不要被名称混淆)只是:

 <?php
   echo $_POST['text'];
 ?>

我期望 responseText黄色,因为我就是这样发送的,但事实并非如此。但我并没有真正看出问题是什么。这一定是那些容易修复的错误之一。

最佳答案

来自http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp :

xmlhttp.open("POST","ajax_test.asp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Henry&lname=Ford");

关于php - responseText 没有显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14371290/

相关文章:

php - 文档存储在 phpmyadmin 与网站文件夹中?

javascript - typescript - while 循环 for Promise

ajax - Ajax 应用程序中的 Facebook 转化跟踪像素

javascript - 使用ajax发送两个表单一个提交按钮

php - 在 NetBeans/Eclipse/PHPstorm (AJAX API) 中使用 $_GET 参数调试单个 PHP 文件

php - 嵌套评论背后的算法是什么?

php - 通过 TLS 的显式 FTP 失败 : Warning: ftp_fput(): data_accept: SSL/TLS handshake failed

php - 有没有办法检索类常量的 PHPDoc 注释?

javascript - 如何从 JSON 继承获取 JavaScript 对象?

php - 我的代码有什么错误?