[JQ/PHP] Let's talk about the use of JS array stored values (submitted for PHP processing) and jqjs

Source: Internet
Author: User

[JQ/PHP] Let's talk about the use of JS array stored values (submitted for PHP processing) and jqjs

Bytes ---------------------------------------------------------------------------------------------------

From an example, we can see the division of labor between JS arrays and objects:

/**
* JS arrays and objects are used. (multiple json data records are transmitted, and the instance is partial)
* @ Blackeye poet <www. chenwei. ws>
*/Function importL () {if (confirm ('sure? ') {Var arr = []; var json = {}; var type_code = $ ('select [name = "type_code"]'); // select label node var le = $ ('input [name = "le []"] '); // checkbox node $. each (le, function (I, n) {if (n. checked) {info = {"type_code": type_code.val (), "code": $ (this ). val (), "the_name": $ (this ). attr ('the _ name')}; var info = JSON. stringify (info); // convert it to the json string arr. push (info); // store multiple json strings into arrays} json. all = arr; // save the entire array to a json object. The key is All (the reason is that the ajax parameter passing format is json)}); if (arr. length = 0) {my_custom_tips ('error1 ');} else if (type_code.val () = 0) {my_custom_tips ('error2');} else {$. ajax ({type: 'post', url: base_url + '? D = admin & c = api & m = ajax_import ', data: json, success: function (data) {console. log (data );}});}}}

 

After the data is successfully received, the processing is simple:

/**
* PHP processes data
* @ Blackeye poet <www. chenwei. ws>
*/
Public function ajax_import ()
{
$ Info = $ this-> input-> post ('all ');
Foreach ($ info as $ val) {$ arr [] = json_decode ($ val, true );}

Print_r ($ arr );
}

/*
The format of the processed data is as follows to facilitate processing:
Array ([0] => Array ([type_code] => 111 [code] => 222 [the_name] => www. chenwei. ws) [1] => Array ([type_code] => 333 [code] => 444 [the_name] => implement simplicity to the extreme ))
*/

Earlier: [jQ/PHP] used JS array to store values in two cases (submitted for PHP processing)

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.