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
  • 写回答

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');
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog