How does PHP receive the ajaxPOSTjson object to PHP?

Source: Internet
Author: User
The ajaxPOSTjson object is sent to PHP. how does PHP receive the value on the frontend:
$ ("# Save_config_btn "). click (function () {$. ajaxSetup ({cache: false, contentType: "application/x-www-form-urlencoded; charset = utf-8"}); var fields = $ ("# rss_form "). serializeArray (); fields = JSON. stringify (fields) // garbled characters in Chinese $. ajax ({type: "POST", url: "edit. php ", data: fields, success: function (msg) {alert (msg );}});});

PHP:
 ';print_r($data);?>

The JSON format obtained through json. stringify is as follows:
 [{ "name":"Bill" , "value":"Gates" },{ "name":"George" , "value":"Bush" },{ "name":"Thomas" , "value":"Carter" }]

PHP. here, the POST receiving value does not know what to use. if you change the above json string to the following format, PHP can accept and directly return the array format.
 {"data":[{ "name":"Bill" , "value":"Gates" },{ "name":"George" , "value":"Bush" },{ "name":"Thomas" , "value":"Carter" }]}

To sum up, I want to ask two questions:

1. how does JQuery convert the json object obtained by serializeArray () to a json string in the second format and ensure that Chinese characters are not garbled?

2. how can php directly receive json objects or json strings in the first format?


Reply to discussion (solution)

1. how does JQuery convert the json object obtained by serializeArray () to a json string in the second format and ensure that Chinese characters are not garbled?

Ensure no garbled characters. you must add them to the header.


Second array format
Var fields = $ ("# rss_form"). serializeArray ();
Var t = {};
T ['data'] = fields
Fields = JSON. stringify (t );

2. how can php directly receive json objects or json strings in the first format?
Use the first json string to submit an example:

   
   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.