$host = 'localhost';
$user = 'root';
$pass = '';
$db_name="bbbb";
$conn = new mysqli($host, $user, $pass, $db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$data = array(); // create an array
while( $row = $result->fetch_assoc()) {
echo $row ['input']; //if my database have 2 rows one with value t1 and other with t2.
}
?>
第二档:
<script src = "https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script>
$(document).ready(function(){
retrieveData();
});
function retrieveData(){
$.post('quick.php',{}, function(data){
window.alert(data);
});
}
</script>
我的输出是一个警报(t1 t2) 我希望输出为2个警报窗口。第一个值为t1,第二个值为t2。
答案 0 :(得分:0)
试试这个: 使用json到你的服务器端,
while( $row = $result->fetch_assoc()) {
echo json_encode($row['input']);
}
并在您的第二个文件中:
$.post('quick.php',{}, function(data){
window.alert(data);
},"json");