我遇到了问题
我的页面中有一个脚本可以执行一些操作,例如从表中删除一行,添加一行 在jquery ajax的表格中。
但是当我用ajax添加一行新行时,这行不起作用。
所以有一种方法可以每N秒重新加载一次这个脚本吗?!?
<script>
.... some stuff ....
setInterval(function() {
#reload script or something like that
},2000);
</script>
例如,此功能点击打开一条消息......
HTML
<table>
<tr class='MessageList' id='a_1'><td>1</td></tr>
<tr class='MessageList' id='a_2'><td>2</td></tr>
<tr class='MessageList' id='a_3'><td>3</td></tr>
</table>
JS
$('.MessageList').click(function(){
var id=this.id;
if(openMessage)
{
if($('#read-message').attr('message')==$('#'+id).attr('data'))
{
$('#message-list').addClass('hide');
$('#read-message').removeClass('hide');
}
else
{
var readMsg=true;
if($('#'+id).hasClass('not_viewed'))
{
readMsg=false;
jQuery.ajax({
type: "POST",
url: "<?php echo AJAX_RE;?>/nvinbox/",
data: "b=" + $('#'+id).attr('view') + "&a=<?php echo $_SESSION['registrar']['inbox'] ?>",
cache: true,
async: false,
error: function(){
wAlert({ title: "<?php echo $this->languages["PLEASE_TRY_LATER"] ?>",description: "<?php echo $this->languages["SOMETHING_WRONG"] ?>",redirect:'<?php echo USER_REGISTRAR_PAGE?>inbox/'});
},
success: function (response) {
if(response!='No direct script access allowed')
{
var arr = id.split("_");
$('#message_'+arr[1]).addClass('viewed').removeClass('not_viewed');
readMsg=true;
}
else wAlert({ title: "<?php echo $this->languages["PLEASE_TRY_LATER"] ?>",description: "<?php echo $this->languages["SOMETHING_WRONG"] ?>"});
}
});
}
if(readMsg)
{
jQuery.ajax({type: "POST",url: "<?php echo AJAX_RE;?>/upinbox/",dataType : "json",
success: function (response) {
$('#notifMessage').remove();
$('#messageInbox').append(response[0]);
if(response[1]!=0){}
}});
$('#read-message').remove();
jQuery.ajax({
type: "POST",
url: "<?php echo AJAX_RE;?>/vinbox/",
data: "c="+id+"&b=" + $('#'+id).attr('data') + "&a=<?php echo $_SESSION['registrar']['inbox'] ?>",
cache: true,
async: false,
error: function(){
wAlert({ title: "<?php echo $this->languages["PLEASE_TRY_LATER"] ?>",description: "<?php echo $this->languages["SOMETHING_WRONG"] ?>",redirect:'<?php echo USER_REGISTRAR_PAGE?>inbox/'});
},
success: function (response) {
if(response!='No direct script access allowed')
{
var arr = id.split("_");
$('.email-content').append(response);
$('#message-list').addClass("hide");
$('#read-message').removeClass("hide");
}
else wAlert({ title: "<?php echo $this->languages["PLEASE_TRY_LATER"] ?>",description: "<?php echo $this->languages["SOMETHING_WRONG"] ?>"});
}
});
}
}
}
else openMessage=true;
});
当我在表格中添加新行时
<table>
<!-- new row HERE -> <tr class='MessageList' id='a_1456'><td>1456</td></tr>
<tr class='MessageList' id='a_1'><td>1</td></tr>
<tr class='MessageList' id='a_2'><td>2</td></tr>
<tr class='MessageList' id='a_3'><td>3</td></tr>
</table>
如果我点击新行tr不起作用......但其他工作正常......