How does JavaScript process json-format data returned by php? An example is provided below!
Suppose php returns the following array:
$ Arr = array ('name' => 'qianyuqianxun ', 'Nick' => 'qianxun ', 'Contact' => array ('website' => 'HTTP: // www.phpernote.com '), array ('name' => 'qisha', 'Nick' => 'qizha', 'email '=> 'yhm. 1234@163.com ', 'Contact' => array ('website' => 'HTTP: // www.baidu.com '); print_r (json_encode ($ arr); exit;
The client JS can call the data returned as follows:
$ (Document ). ready (function () {var url = 'HTTP: // www.phpernote.com/json.php'$ ('# submitBtn '). click (function () {$. post (url, '', function (msg) {var myObject = eval ('+ msg +'); // msg is a string of the returned type, convert to json object var str = ''; var len = myObject. length; for (I = 0; I <len; I ++) {str + = '<tr> <td>' + myObject [I]. name + '</td> <td>' + myObject [I]. nick + '</td> <td>' + myObject [I]. contact. website + '</td> </tr> '{}}('{feedbacktable'{.html (str );})})})Articles you may be interested in
- How does jquery process json data?
- PHP number formatting, three digits are added with commas
- Mysql queue for efficient Concurrent Data Reading
- Jquery + html + php implement Ajax without refreshing File Upload
- Rational use of MySQL database indexes to make the database run efficiently
- In php, we use the curl post method to submit data and the get method to obtain webpage data.
- Php gets the method of each month in a certain period of time, and returns an array composed of these months
- Two Methods for connecting PHP to access database