使用单页面中的ajax加载多个数据

时间:2013-11-24 20:18:21

标签: javascript php jquery ajax

我有以下代码从php页面获取http响应工作正常,但我想知道我是否可以在该php页面上有另一个查询并在主页面上显示该数据。我可以为每个请求创建一个页面吗?

$(document).ready(function() {
    loadData();
});

var loadData = function() {
    $.ajax({    //create an ajax request to load_page.php
        type: "GET",
        url: "second.php",             
        dataType: "html",   //expect html to be returned                
        success: function(response){                    
            $(".display").html(response);
            setTimeout(loadData, 1000); 
        }

    });
};

second.php

 //first query
$inbox = $msg->prepare("SELECT * FROM messages where to_user = ?  and deleted != ? and del2 != ? and is_read = '' order by id desc");
 echo $msg->error;
 $inbox->bind_param('sss', $username->username, $username->username, $username->username );
 $inbox->execute();
 $unread = $inbox->get_result();

   //second query
  $stmt2 = $msg->prepare("");
  $stmt2->bind_param('', $var....

HTML

 <div class="display"></div><!--The response is displayed here-->

  <div></div><!--I want the the result of second query to be displayed here-->

0 个答案:

没有答案