【问题标题】:Changing ajax function to modal bootstrap将 ajax 函数更改为模态引导程序
【发布时间】:2013-07-14 10:10:59
【问题描述】:

我一直在尝试为我的网站使用引导模式。现在我需要更改以下代码以与模态一起使用

$(document.body).on('click','.socialIcon',null,function() {
    var id = $(this).attr('id').replace('social_','');
    var win = function(resp) {
        var dialogWin = $('#socRegPopup');
        if(dialogWin.length){
            dialogWin.remove();
        }
        $('#wrapper').append(resp);  
        dialogWin = $('#socRegPopup');
        dialogWin.dialog({ 
            autoOpen: true,
            width: 515,
            modal: true,
            position: 'center',
            resizable: false
        });
    };
    $.ajax({
        url: liveSite +'/index2.php?obj=social&task=getSocialForm',
        type:'get',
        data: {programId: id},
        success:win});    
});

我尝试将其更改为使用引导模式

$(document.body).on('click','.socialIcon',null,function() {
    var id = $(this).attr('id').replace('social_','');
    var win = function(resp) { 
        $('#wrapper').append(resp);  
        $('#socRegPopup').modal();
    };
    $.ajax({
        url: liveSite +'/index2.php?obj=social&task=getSocialForm',
        type:'get',
        data: {programId: id},
        success:win});    
});

这个可行,但问题是数据没有改变 例如,当我单击按钮 1 时有 3 个按钮,它将输出正确,但接下来的所有按钮将输出按钮 1 数据。任何指南如何使模态在 ajax 上工作

【问题讨论】:

    标签: javascript ajax twitter-bootstrap


    【解决方案1】:

    这解决了我的问题。我不知道这是否是一个更好的解决方案

    $(document.body).on('click','.socialIcon',null,function() {
        var id = $(this).attr('id').replace('social_','');
        var win = function(resp) { 
    
            var element = document.getElementById("socRegPopup");
            if(element){
            element.parentNode.removeChild(element);
         } 
    
            $('#wrapper').append(resp);  
            $('#socRegPopup').modal();
        };
        $.ajax({
            url: liveSite +'/index2.php?obj=social&task=getSocialForm',
            type:'get',
            data: {programId: id},
            success:win});    
    });
    

    【讨论】:

      猜你喜欢
      • 2019-02-14
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      相关资源
      最近更新 更多