A
A
alex_dark2015-09-27 09:49:37
JSON
alex_dark, 2015-09-27 09:49:37

Why does passing json via pjax post create so many variables?

Hello!
I receive data from one service in the form of a json object. I do it in javascript'e
Then I want to transfer this data to the server via pjax. With the post method
When I do this, pjax creates its own variable for each key in the object.
As a result, if I pass suppose

var info = {
    "id": 64479477,
    "first_name": "Сергей",
    "last_name": "Мишин",
    "sex": 2,
    "nickname": "",
    "screen_name": "sergey_mishin",
    "bdate": "6.6.1987"
  }

with a query like this:
$.pjax.reload({
      container  : '#content',
      type       : 'POST',
      url        : path,
      data       : info,
      push       : true,
      replace    :  false,
      timeout    : 1000
    });

then in the post request flies
info[id]:64479477
info[first_name]:Сергей
info[last_name]:Мишин
info[sex]:2
info[nickname]:
info[screen_name]:sergey_mishin
info[bdate]:6.6.1987

Is this how it should be and am I missing something?
Or am I doing something wrong?
And if I'm doing it wrong, then how can I pass json so that many variables are not created?
Of course, you can wrap it in stringify, and parse it on the server. But it would not be desirable
================
UPD
After studying the issue, it was found that ajax/pjax work like that. And that's right. And so it should be. Don't do anything about it. If a small amount of data needs to be transferred, don't worry.
If we are talking about thousands of variables (which will significantly increase the data load), then it would rather be better to transfer the data as a string
$.pjax.reload({
      container: '#content',
      type: 'POST',
      url: path,
      data: {
        jsonData: JSON.stringify(data)
      },
      push: true,
      replace: false,
      timeout: 1000
    });

and on the server do json_decode($_POST['jsonData']);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question