WKoA
WKoA

Reputation: 21

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?

Upvotes: 0

Views: 3548

Answers (4)

Electronick
Electronick

Reputation: 1122

And you can use

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

if not shure how it should be get.

Upvotes: 0

Matt Reid
Matt Reid

Reputation: 235

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.

Upvotes: 1

Maurice Perry
Maurice Perry

Reputation: 32831

Use $_POST instead of $_GET...

Upvotes: 0

fyr
fyr

Reputation: 20859

The variable values are not included in $_GET you might find them in $_POST

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

Upvotes: 5

Related Questions