Ajax passing arrays

Source: Internet
Author: User

Use Json.stringify () in the JQ code in the foreground to convert the array to a JSON string, and Json_decode () in the background to convert the JSON string into a group.

1,json.stringify (value [, Replacer] [, space])

Value: is a required field. is an object, an array, a class, and so on.

Replacer: is an optional field. It is divided into 2 different ways, one is an array, the second is a method.

Case one: When Replacer is an array, it is related to the first parameter, value. In general, serialization results are represented by key-value pairs. Therefore, if the value of the second parameter is present at the first, then the value of the second parameter is the key, the value of the first parameter is the expression of value, and if it does not exist, it is ignored.

Situation two: Replacer as a method, that is very simple, that is, the serialization of each object (remember that every one) into the method of processing.

Space: is an optional field. What makes a delimiter.

2,Json_decode ()

Json_decode ( string $json [, bool $assoc = False [, int $depth = int $options = 0]]]) 21>

< Span class= "type" > < Span class= "initializer" > json: json string

< Span class= "type" > < Span class= "initializer" >ASSOC: When this parameter is TRUE , an array is returned

< Span class= "type" > < Span class= "initializer" >depth: User-specified recursion depth.

< Span class= "type" > < Span class= "initializer" >options:json bitmask option.

< Span class= "type" > < Span class= "initializer" > 3, example

< Span class= "type" > < Span class= "initializer" >   front desk:

< Span class= "type" > < Span class= "initializer" >              var arr=new Array (+/-);

var operatorids=json.stringify (arr);//Convert an array to a JSON string

$.ajax ({
Type: ' Post ',
Data: {' text ': text, ' Operatorids ': Operatorids},
URL: ' <?php echo $this->createurl (' letter/sendletters ');? > ',
Success:function (data) {
alert (data);
}

Background:

$model->operatorids= Json_decode (Yii::app ()->request->getparam ("Operatorids");

Ajax passing arrays

Related Article

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.