javascript - Replace inner HTML of a div with Ajax response -
i trying alter inner html of div after interval. getting right response want ajax. unable replace inner html of selected after , ajax response. wrong code..
html
<p class="time ui-li-desc" data-time="2013-02-13 11:30:08" > 51 seconds ago<img alt="image" src="images/read.png"></p> <p class="time ui-li-desc" data-time="2013-02-13 11:30:16" > 58 seconds ago<img alt="image" src="images/read.png"></p> . . . . . <p class="time ui-li-desc" data-time="2013-02-13 11:40:08" > 10 min ago<img alt="image" src="images/read.png"></p>
j query
setinterval(function() { $( ".time" ).each(function( index ) { var sendtime= $(this).attr("data-time"); datastring = "sendtime="+sendtime+"&q=converttime"; $.ajax({ type: "post", url: "data_handler.php", data: datastring, cache: true, success: function(response) { alert(response); $(this).html(response); //alert(response); } }); }); }, 5000);
this
window in callback. utilize value given callback
of each :
$( ".time" ).each(function(index , elem) { var sendtime= $(this).attr("data-time"); datastring = "sendtime="+sendtime+"&q=converttime"; $.ajax({ type: "post", url: "data_handler.php", data: datastring, cache: true, success: function(response) { alert(response); $(elem).html(response); } }); });
you don't need define new variable protect this
jquery you.
javascript jquery html ajax
No comments:
Post a Comment