我试图显示加载图像,直到 php 执行,查询在第二页上有效,但结果没有显示在第一页上,我知道我在这里遗漏了一些东西,有人可以帮我吗?我是 jquery 或 ajax 的新手。
主页.php
<html>
<head>
<!--Javascript-->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$('#loading_spinner').show();
var post_data = "items=" + items;
$.ajax({
    url: 'list.php',
    type: 'POST',
    data: post_data,
    dataType: 'html',
    success: function(data) {
        $('.my_update_panel').html(data);
    },
    error: function() {
        alert("Something went wrong!");
    }
});
$('#loading_spinner').hide();
</script>
<style>
   #loading_spinner { display:none; }
</style>
</head>
<body>
<img id="loading_spinner" src="image/ajax-loader.gif">
<div class="my_update_panel">
<!--I am not sure what to put here, so the results can show here-->
</div>
list.php我测试了查询并打印了行。
<?php
   include_once("models/config.php");
   // if this page was not called by AJAX, die
   if (!$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') die('Invalid request');
   // get variable sent from client-side page
   $my_variable = isset($_POST['items']) ? strip_tags($_POST['items']) :null;  
       //run some queries, printing some kind of result
   $mydb = new mysqli("localhost", "root", "", "db");
   $username = $_SESSION["userCakeUser"];
       $stmt = $mydb->prepare("SELECT * FROM products where username = ?");
   $stmt->bind_param('s', $username->username);
   $stmt->execute();
   // echo results
   $max = $stmt->get_result();
   while ($row = $max->fetch_assoc()) {
      echo $row['title'];
       echo $row['price'];
      echo $row['condition'];
   }
?>