<! 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