. HTML()不能在jquery $.post之后实时更新HTML表

.html() not working for live update of html table after jquery $.post

本文关键字:HTML post 之后 实时更新 jquery 不能      更新时间:2023-09-26

我目前有一个jQuery对话框(http://api.jqueryui.com/dialog/),当用户单击类low_inv_notes的表时,将弹出并允许他们输入他们想要的任何注释。

注释被正确地存储在数据库中,但是我试图实现表td的实时更新,当他们在那个对话框上点击提交,这是不工作。如果用户想要看到更新的表,他们必须重新加载页面,这不是我想要的。

我相信我的问题与。html()有关;我已经发出警报,检查我使用的变量有值,我已经检查了,以确保所有的id和类的正确标签。

下面是我的对话框的代码:

 $( ".low_inv_notes" ).click(function(event) {
var notes = $(this).andSelf().html();
var netQty = $(this).closest('tr').find('td:eq(6)').text();
var stockNumber = $(this).closest('tr').find('td:eq(0)').text();

    var $dialog = $('<div id="dialog"></div>')
        .html('<textarea id="noteContent" style="width: 450px; height: 190px;">' + notes + '</textarea>')
        .dialog({ title: 'Edit This Note:',
                    autoOpen: false,
                    height: 300,
                    width: 500,
                    modal: true,
                    buttons: {
                      "Submit":function() {
                             var old = notes;
                             var new_notes =  $("#noteContent").val();
                            if(new_notes == old){
                                 alert("Note is the same - change to submit"); 
                                 $(this).dialog('close');
                                 $(this).dialog('open');
                             }
                             else {
                                     $.post( "edit_low_inv_notes.php", { netQty:netQty, stockNumber: stockNumber, new_notes: new_notes},function(data){
                                            var id = stockNumber+'notes';
                                            //alert(id);
                                            //alert(new_notes);
                                            //$('#00260040.01Dnotes').html('test');
                                            $('#'+id).html(new_notes);
                                            }
                                    );

                            $(this).dialog("destroy").remove();
                             }
                      },
                      "Close":function() {  
                            $(this).dialog("destroy").remove();
                      } 
                    }
                });
  $dialog.dialog( "open" );
 });

我已经尝试将。text替换为。html以及在函数(数据)之前完成相同数量的成功。什么好主意吗?提前感谢

我强烈怀疑问题在于元素id中间的.字符。如果你的id值真的看起来像"00260040.01D",那么jQuery将把.解释为一个类选择器。

你可以试试:

$('#' + id.replace(/'./g, '''.')).html(new_notes);