douguadao3883
2014-11-26 01:03
浏览 35

jQueryUI模式确认删除了ajax加载的行

I have a PHP script (ajax.php) which loads content from a MySQL db. That script refreshes new content every N seconds via AJAX. The AJAX content has three links of which one is to archive the row in MySQL. When a user clicks the archive button, I want a jQueryUI dialog to open confirming deletion. Pressing cancel will abort, while OK will trigger an AJAX submission to delete the row from MySQL. Deleting row from table with modal form confirmation (jQuery UI)? is an example of the dialog half of what I want to do. I need this to work along with the ajax/refresh.

Because of the link itself being loaded by AJAX, I cannot run the dialog (or the delete script). How do I load the dialog script and perform the AJAX delete submission? I'm trying to use the GlobalEval but I do not understand the documentation. The examples I've found seem to be for setting variables only. The following script is what I'm trying to build it from:

var id = $('.refreshN').data('id');
var table = $('.refreshN').data('table');
var rtime = $('.refreshN').data('time');
$('.refreshN').load('ajax.php?id='+id+'&table='+table).fadeIn("slow");

var autoLoad = setInterval(
function ()
{
    $('.refreshN').load('ajax.php?id='+id+'&table='+table).fadeIn(5000);
    var script = $(function (){
        $('.modalLink').click(function () {
            $('#dialog').dialog('open');
            return false;
        });
    });
    eval(script);
}, rtime); // refresh page every N seconds

图片转代码服务由CSDN问答提供 功能建议

我有一个PHP脚本(ajax.php),它从MySQL数据库加载内容。 该脚本通过AJAX每N秒刷新一次新内容。 AJAX内容有三个链接,其中一个是在MySQL中存档行。 当用户单击存档按钮时,我想要一个jQueryUI对话框打开确认删除。 按取消将中止,而OK将触发AJAX提交以从MySQL删除该行。 使用模态表单确认(jQuery UI)从表中删除行 ?是我想要做的对话的一半示例。 我需要它与ajax / refresh一起工作。

由于链接本身是由AJAX加载的,我无法运行对话框(或删除脚本)。 如何加载对话框脚本并执行AJAX删除提交? 我正在尝试使用GlobalEval,但我不懂文档。 我发现的例子似乎只是用于设置变量。 我正在尝试构建以下脚本:

  var id = $('。refreshN')。data('id'); 
var table =  $('。refreshN')。data('table'); 
var rtime = $('。refreshN')。data('time'); 
 $('。refreshN')。load('ajax.php  ?id ='+ id +'& table ='+ table).fadeIn(“slow”); 
 
var autoLoad = setInterval(
function()
 {
 $('。refreshN')。load(  'ajax.php?id ='+ id +'& table ='+ table).fadeIn(5000); 
 var script = $(function(){
 $('。modalLink')。click(function(function)  ){
 $('#dialog')。dialog('open'); 
 return false; 
}); 
}); 
 eval(script); 
},rtime);  //每N秒刷新一次页面
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douping3860 2014-11-26 06:59
    已采纳

    Define the variable script with an normal javascript function and add () to execute it. Try this instead of your current js:

    var id = $('.refreshN').data('id');
    var table = $('.refreshN').data('table');
    var rtime = $('.refreshN').data('time');
    $('.refreshN').load('ajax.php?id='+id+'&table='+table).fadeIn("slow");
    
    var autoLoad = setInterval(
    function ()
    {
        $('.refreshN').load('ajax.php?id='+id+'&table='+table).fadeIn(5000);
    }, rtime); // refresh page every N seconds
    
    $(document).on('click','.modalLink',function(e){
        e.preventDefault();
        $('#dialog').dialog('open');
    })
    
    打赏 评论

相关推荐 更多相似问题