Q
Q
Qubert2014-07-24 14:07:32
PHP
Qubert, 2014-07-24 14:07:32

How to accept object in php in this case?

I have jquery code:

var wizard_object = JSON.stringify(newThemeWizard);

            $.ajax({
               type : 'POST',
               url : 'index.php',
               data: "data="+wizard_object,
               success: function(res){
                 console.log(res);
               }

            });


in php you can accept it so
var_dump(json_decode($_POST['data'], true));

if i pass an object how can i refer to it else? more specifically refer to its specific data?

Thank you

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Entelis, 2014-07-24
@DmitriyEntelis

$a = json_decode($_POST['data']);
var_dump ($a->someproperty);

If you are talking about it

S
Sergey, 2014-07-24
Protko @Fesor

Discover the joy of abstractions over requests/responses. Avoid superglobals, use HttpKernel (or your own implementation). Pass json to the POST Body in general, and on the PHP side do json_encode for php://input (if we have Content-type: application/json in the request headers).
Learn to do things right.

S
Sergey Melnikov, 2014-07-24
@mlnkv

js:

$.post("index.php", { data: newThemeWizard }, function(resp) {
  console.log(res);
});

php:
$data = json_decode($_POST['data']);
$data->some_property; //получаем данные

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question