[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)