• Interaction1


    var xmlhttp = new XMLHttpRequest();
    		xmlhttp.open("GET","connectDatabase.php",true);
    		xmlhttp.send();
    	xmlhttp.onreadystatechange= function(){
    		if(xmlhttp.readyState ==4 && xmlhttp.status ==200){
    			str = xmlhttp.responseText;
    			// console.log(typeof str);
    			console.log(str);
    			json_str = JSON.parse(str); //将返回json字符串转为js对象
    			console.log(json_str);
    
    <?php
     		$servername  = 'localhost';
     		$username = 'root';
     		$password = '';
     		$db = 'mydb';
     		// $name1 = $_GET["fname"];
     		// echo $name1;
     		$con = mysqli_connect($servername,$username,$password,$db);
     		if($con->connect_error){
     			die("error".$con->connect_error);
     		}
     		// echo "connect ok!";
    
    
     		$result = mysqli_query($con,"select firstname, lastname,email from myguests");
     		     $arr=[];
    			while($row= mysqli_fetch_array($result,MYSQLI_ASSOC)){
     			// print_r($row);
     			// $arr[] = $row;   
    				array_push($arr,$row);
    			}
    			// print_r($arr);
    			// echo "-------------------";
     			echo json_encode($arr); //将数组对象转为json字符串
     		$con->close();
     		?>
    
  • 相关阅读:
    Linux私房菜——防火墙部分笔记
    ubuntu
    序列求和
    圆的面积
    Fibonacci数列
    JavaScript中定义数组
    C语言中的EOF
    jQuery获取的值去掉px
    jQuery中单引号和双引号的使用
    jQuery报错:Uncaught ReferenceError: $ is not defined
  • 原文地址:https://www.cnblogs.com/cyany/p/8465777.html
Copyright © 2020-2023  润新知