How JavaScript handles PHP data returned in JSON format _php tutorial

Source: Internet
Author: User
Tags how to use curl
How JavaScript handles PHP's return to JSON-formatted data, as described below in an example!

Suppose PHP returns an array of the following:

$arr = Array (' name ' = ' Qianyuqianxun ', ' nick ' = ' thousand and Chihiro ', ' Contact ' =>array (' website ' = '/' Www.phpernote.com '), Array (' name ' = ' Qisha ', ' nick ' = ' seven evil spirit ', ' email ' = ' yhm.1234@163.com ', ' contact ' + = Array (' website ' = ' http://www.baidu.com '));p Rint_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 the returned type as a string, converted to a JSON object var str= '; var len=myobject.length; for (i=0;i
 <>
  ' +myobject[i].name+ ' +myobject[i].nick+ ' +myobject[i].contact.website+ ';} $ (' #feedbackTable '). html (str);})})
 

Articles you may be interested in

    • How jquery handles JSON data
    • PHP digital format, numbers every three bits plus commas
    • MySQL queue for efficient concurrent read data
    • jquery+html+php implement Ajax no-refresh file upload
    • Use MySQL database indexes reasonably to make the database run efficiently
    • How to use Curl's post submission data in PHP and get a summary of how to get Web page data
    • PHP gets a method for each month in a certain period of time, returning an array of these months
    • PHP two ways to connect to an Access database

http://www.bkjia.com/PHPjc/764170.html www.bkjia.com true http://www.bkjia.com/PHPjc/764170.html techarticle how JavaScript handles PHP's return to JSON-formatted data, as described below in an example! Suppose PHP returns the following array: $arr = Array (' name ' = ' Qianyuqianxun ', ' N ...

  • 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.