简体   繁体   English

Ajax发布数据并使用php收集数据

[英]Ajax post data collecting data with php

I'm a bit lost when it comes to posting data using Ajax. 当使用Ajax发布数据时,我有点迷茫。 This is the code im using: 这是我使用的代码:

ajaxRequest.open("post", "serverTime.php", true);
ajaxRequest.send(somedata); 

Im not sure how i get hold of this data in my php script? 我不确定我如何在PHP脚本中掌握这些数据? How what i know what its called? 我怎么知道它叫什么? is it just called 'somedata' Also what if i want to use multiple variables to pass through? 它只是被称为“ somedata”吗?如果我想使用多个变量来传递呢?

I think theres just something silly im over looking but i'm really struggling to find what im looking for on the internet 我认为在寻找即时消息时有些愚蠢,但我真的很难在网上找到即时消息

Thanks hope you can help. 希望您能提供帮助。

http://www.openjs.com/articles/ajax_xmlhttp_using_post.php http://www.openjs.com/articles/ajax_xmlhttp_using_post.php

// excerpt
var url = "get_data.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);

http.send(params);

In get_data.php you can call them via $_POST : 在get_data.php中,您可以通过$_POST来调用它们:

echo $_POST['lorem']; // == ipsum
echo $_POST['name'];  // == binny

Example here: http://www.openjs.com/scripts/examples/ajax_using_post.php 此处的示例: http : //www.openjs.com/scripts/examples/ajax_using_post.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM