The Ajax return data type in PHP is the processing of JSON data

Source: Internet
Author: User

<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >$.Ajax ({URL: "Jsonchuli.php",DataType: "JSON",Success:function(data) {varstr = ""; /*For (var i=0;i<data.length;i++)//The case of the associative array and the capitalization inside the database should be consistent. {str = str+ "<option value= '" +data[i]. Code+ "' >" +data[i].            Name+ "</option>"; } $ ("#nation"). html (str);*/                         for(varK in data)//This method is equivalent to the Foreach method traversal, and the method above is a for loop. {str= str+ "<option value= '" +data[k]. Code+ "' >" +data[k]. Name+ "</option>"; }            $("#nation").html (str); }    })</script>
<? PHP include ("./dbda.class.php"); $db New Dbda (); $sql = "SELECT * from Nation"; // The encoding format that requires the use of associative array//array content must be UTF8, others are not possible.  Echo json_encode ($db->query ($sql, 0)); // The associated array is returned. Json_encode returns the JSON data. 

The Ajax return data type in PHP is the processing of JSON data

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.