简体   繁体   中英

How to get javascript post variable in php?

I have a small problem to get jQuery post variables. So i have javascript file where is code bellow:

<script type="text/javascript">
$.post("view.php", { name: "John" } );
</script>

And i try to get that name "John" in view.php file like this:

<?php $variable = $_GET["name"]; ?>

And it wont get that name. Can someone please help me?

变量值不包含在$_GET您可以在$_POST找到它们

<?php $variable = $_POST["name"]; ?>

Since you've used '$.post' you must use the related action which will be $_POST. If you were using '$.get', then you would use your current method of $_GET.

使用$ _POST代替$ _GET ...

And you can use

<?php $variable = $_REQUEST['name']; ?>

if not shure how it should be get.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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