繁体   English   中英

.html()无法在jquery $ .post之后实时更新html表

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

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

便笺已正确存储在数据库中,但是当他们在该对话框上单击“提交”时,我正在尝试实现表td的实时更新,但这不起作用。 如果用户想查看更新的表,他们必须重新加载页面,这不是我想要的。

我相信我的问题与.html()有关; 我已经发出警报来检查我正在使用的变量是否具有值,并且已经检查以确保所有id和class均已正确标记。

这是我目前对话框的代码:

 $( ".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以及在函数(data)之前使用.done获得相同的成功率。 有任何想法吗? 提前谢谢

我强烈怀疑问题出在. 元素ID中间的字符。 如果您的id值确实看起来像“ 00260040.01D”,那么jQuery将解释该值. 作为类选择器。

您可以尝试以下方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM