XMLHttpRequest — passing parameter to PHP file

微笑、不失礼 提交于 2020-06-17 14:19:47

问题


I've got the following XMLHttpRequest:

var xhttp = new XMLHttpRequest();
xhttp.open("POST", "includes/stats.inc.php", true);
xhttp.send("date=" + date);

I want to pass the date variable through to the php file which does some stuff.

I have double checked and the php file does some stuff [without the date variable] if I 'call' it using a form:

<form action="includes/stats.inc.php" method="post">
    <button type="submit" name="login-submit">test</button>
</form>

But it's my understanding I need to use an XMLHttpRequest to pass the variable. I've searched and tried various ways of doing it and it doesn't seem to work. When doing:

xhttp.responseText

it just returns the HTML code. Any ideas? Thank you

来源:https://stackoverflow.com/questions/62150613/xmlhttprequest-passing-parameter-to-php-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!