Using AJAX to find a database

Source: Internet
Author: User
Tags string format

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

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.