Home > Backend Development > PHP Tutorial > php读取js变量的ajax代码

php读取js变量的ajax代码

WBOY
Release: 2016-06-23 13:31:18
Original
923 people have browsed it

如题,网上找了很多代码看,看的好乱,自己尝试了下也没搞定。要求非常简单,只是想php从js中读取一个形参而已,也不需要js再接收什么php的返回值,部分代码如下,求哪位大神帮忙写个,3q
$device = $_POST['phone'];
function count_num()
{
echo $device;
}
?>

<script> <br /> function ShowNumber(device) <br /> { <br /> $.post("check.php", { phone:device } ); <br /> } <br /> </script>


回复讨论(解决方案)

check.php

<?phpecho $_POST['phone'];
Copy after login

不过你没有接收 check.php 处理结果的代码,没法看到

你可以
$.post("check.php", { phone:device }, function(d) {alert(d)} );
这样看一下

也可以
file_put_contents('test.txt', $_POST['phone']);
在 test.txt 中看一下

      $device = $_POST['phone'];
Copy after login

我以为这样就能接收到了,结果提示Notice: Undefined index: phone。
上面写的php和js就是在check.php文件中的,我只是想用php读取js函数ShowNumber()的形成那,然后再根据读取到的形参在数据库中查询满足的值。只是想获得一个形参,返回值什么的都没。
您给我的$.post("check.php", { phone:device }, function(d) {alert(d)} );我试了下,没反应

JQ类引了没了?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template