Can anyone see why this jQu开发者_如何学Pythonery ajax isn't working? It's supposed to run every second, but it isn't running at all.
Source code:
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
var ID = $(this).attr("id");
if(ID)
{
$("#more"+ID).html('<img src="moreajax.gif" />');
$.ajax({
type: "POST",
url: "ajax_more.php",
data: "lastmsg="+ ID,
cache: false,
success: function(html){
$("ol#updates").prepend(html);
$("#more"+ID).remove();
}
});
}
else
{
}
return false;
}, 10000);
var ID = $(this).attr("id");
In the context you've provided $(this)
will resolve to an empty set. Thus your later check if(ID)
will always be false.
You should pass an actual selector to $()
to select the dom element you want to get the ID of.
try removing the:
return false;
also you have the setInterval to run every 10000 ms which is equal to 10 seconds.
精彩评论