<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><Scriptsrc= "Jquery-1.11.2.min.js"></Script><title>Untitled Document</title></Head><Body><SelectID= "Nation"></Select></Body>
<script type= "Text/javascript" >$.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(varSinchData//This method is equivalent to the Foreach method traversal, and the method above is a for loop. {str= str+ "<option value= '" +data[s]. Code+ "' >" +data[s]. Name+ "</option>"; } $("#nation"). html (str); } })</script>
</ HTML >
<? 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->guanquery ($sql)); // The associated array is returned. Json_encode returns the JSON data.
Ajax return data type processing for JSON data