Using an AJAX database
querying data with Ajax<! DOCTYPE html Public"-//w3c//dtd XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >$ (document). Ready (function(e) {$ ("#btn"). Click (function(){ $.Ajax ({URL: "Chuli1.php",DataType: "TEXT",Success:function(data) {//alert (data); varstr = "<tr><td> code </td><td> name </td></tr>"; varHang = data.Split("|"); for(vari=0;i) { varLie = Hang[i].Split("^"); //str+= "<tr><td> +lie[0]+" </td><td> "+lie[1]+" </td><td> Delete </td></ Tr> ";Str+ = "<tr>"; for(varj=0;j<lie.length;j++) {str+ = "<td>" +lie[j]+ "</td>"; } STR+ = "</tr>" } $("#xianshi").html (str); } }); }) }); </script>Processing the page: mainly about the two-dimensional number assembly into a string form
<?PHPinclude(".. /test0506/dbda.class.php ");$db=NewDbda ();$sql= "SELECT * FROM Nation"; $attr=$db->query ($sql);//returns a two-dimensional array//converts a two-dimensional array to a string format because Ajax returns the text format of the//echo "p001^ han |p002^ Manchu |p003^ hui";//similar to this format can be $str= "";foreach($attr as $v){ //$str = implode ("^", $v);//$v contains a single piece of data, between the columns and the $str=$str.implode("^",$v);//Otherwise, it will be replaced when you cycle again . $str=$str."|"; } $str=substr($str, 0,strlen($str)-1);//length of intercept stringEcho $str;
Show results
Using AJAX to find a database