Can anyone see why this jQuery 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);
In the context you’ve provided
$(this)will resolve to an empty set. Thus your later checkif(ID)will always be false.You should pass an actual selector to
$()to select the dom element you want to get the ID of.