.html工作,但文本不会在ajax请求后出现

.html work, but text not appear after ajax request

本文关键字:请求 ajax 工作 文本 html      更新时间:2023-09-26
在ajax调用后,我将div buf附加到某个消息框中,但在重新打开对话框后会出现文本。在Chrome、firefox、IE 8上,这很好用,但在IE 7中不行。


编辑:我有一个对话框,点击链接就会打开。然后我执行ajax请求并得到一条消息。单击对话框中的按钮后,此消息应显示在对话框窗口中(在某些div中(。但在IE7中,对话框窗口重新打开后会出现消息。

$("#promised_pay_dialog").dialog({
        buttons: {
            "some button": function(){
                if ($('#confirm').is(':checked')) {
                    $.ajax({
                        url: 'ajax/promisedPayment',
                        type: "POST",
                        data: {
                            subsId:$("#sid").val()
                        },
                        success: function(buf){
                            $('#message_box').html(buf);
                            return false;
                        }
                    });
                }
                else {
                    alert("some message");
                }
            },
            "some button": function() {
                $(this).dialog("close");
            }
        },
        show: {
            effect: "blind",
            duration: 1000
        },
        hide: {
            effect: "explode",
            duration: 1000
        },
        modal: true,
        resizable: false,
        width: 550,
        height: 250
    });

解决了问题,但不能令人满意

单击链接时,调用不带参数的函数createDialog("")。ajax请求后,接收消息并调用createDialog(buf)。但我认为这不是一个好的解决方案。有什么想法吗?

function createDialog(mess){
    $('#message_box').html(mess);
    $("#promised_pay_dialog").dialog({
        buttons: {
            "some button": function(){
                if ($('#confirm').is(':checked')) {
                    $.ajax({
                        url: 'ajax/promisedPayment',
                        type: "POST",
                        data: {
                            subsId:$("#sid").val()
                        },
                        cache:false,
                        success: function(buf){
                            createDialog(buf);
                        }
                    });
                }
                else {
                    alert("some message");
                }
            },
            "some button": function() {
                $(this).dialog("close");
            }
        },
        show: {
            effect: "blind",
            duration: 1000
        },
        hide: {
            effect: "blind",
            duration: 1000
        },
        modal: true,
        resizable: false,
        width: 550,
        height: 250
    });
}

.html()了解IE6-8 的问题

尝试更换以下

$('#message_box').html(buf);

带有

$('#message_box').empty().html(buf);