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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分