如何处理加载事件并在jquery中追加

Hi I have a problem while using set interval function with .load events and append please explain what I did mistake in my code please give a solution

HTML

<div id="user2<?php echo $d['qid'] ;?>">

Comments Loads Here

Jquery code

 setInterval(function(){

  $("#user2").load( "test2.php,#user2");

   },1000); 

qid means Query id I have multiple(qid) queries in my site How to add append please give a solution I am new in jquery Thanks in advance

Id of div is dynamic, as "qid" is appended to it.

<div id="user2<?php echo $d['qid'] ;?>">

In above code, if "$d['qid']" is 101, then generated html will be as given below.

<div id="user2101">

Hence, your javascript must include dynamic id using "" syntax. Also, you should be using space instead of comma in load event (http://api.jquery.com/load/#loading-page-fragments). You should be passing "qid" to "test2.php" page as query string to get comments related to "qid".

setInterval(function(){

  $("#user2<?php echo $d['qid'] ;?>").load( "test2.php #user2");

   },1000);

</div>

First, as qid is the query id. Having the following code with qid 2 will yield

<div id="user22">

Is this really the div you really want? If you want user2 it should be:

<div id="user<?php echo $d['qid'] ;?>">

Second, you need to pass a valid path to your page you want to load. Are you sure test2.php,#user2 is the correct path?