tucnak
tucnak

Reputation: 406

jQuery and $.post

I am using that:

 $.post("src/php/login.php",{
    "user" : {
        "username" : $("#login").val(),
        "password" : $("#pass").val(),
    }
 }, function ( response ) {
    alert(response);
    $("#but").removeAttr("disabled");
 });

And how I can get this json object at php:

 $q = json_decode($_POST[?]);

What I have to set of '?' ?

Upvotes: 2

Views: 818

Answers (2)

Niels
Niels

Reputation: 49909

You can do $_POST['user'] on the PHP side. And you don't have to do a json_decode, because it will be posted as an array with this structure. e.g.:

$_POST['user']['username']
$_POST['user']['password']`

Upvotes: 3

Joe
Joe

Reputation: 82554

user will work:

$_POST["user"];

Upvotes: 1

Related Questions