[英]How to return data to a jquery ajax callback function?
How to return data to a jquery ajax callback function in which the data is coming from a PHP mysql query.. 如何将数据返回到jquery ajax回调函数,其中数据来自PHP mysql查询。
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$.post("getMySqlData", function(data){
});
});
</script>
here's the PHP code which perform the mysql query to select data from a mysql database 这是执行mysql查询以从mysql数据库中选择数据的PHP代码
<?php
$host = "127.0.0.1";
$user = "root";
$password = "problem2";
$database = "scsi_test_log";
$cxn = mysqli_connect($host, $user, $password, $database) or die ("couldnt connect to server");
$query = "SELECT test_header FROM scsi_test";
$result = mysqli_query($cxn, $query) or die ("Couldn't execute query.");
?>
Fetch the result into an array, and echo that in JSON encoding ; 将结果提取到数组中,并以JSON编码回显 ;
$rows = array();
while ( $row = mysqli_fetch_assoc( $result ) ) {
$rows[] = $row;
}
echo json_encode( $rows );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.