dou12754 2013-09-26 18:33
浏览 47

显示加载图像php

I am trying to show loading image until php excutes, the query works on the second page but the results aren't showing on the first page, I know I am missing something here, can someone help me out? I am new to jquery or ajax thing.

home.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 I tested the query and it prints the rows.

<?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'];

   }

?>
  • 写回答

4条回答 默认 最新

  • doukai2839 2013-09-26 18:45
    关注

    There is a issue with

    var post_data = "items=" + items;

    Make it

    $(document).ready(function(){
            $('#loading_spinner').show();
    $.ajax({
        url: 'list.php',
        type: 'POST',
        data: {"items":items},
        dataType: 'html',
        success: function(data) {
            $('.my_update_panel').html(data);
            $('#loading_spinner').hide();     
        },
        error: function() {
            alert("Something went wrong!");
        }
    });
    });
    

    let me know if works for you.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀