对话框输入在ajax调用之前传递submit的值

时间:2016-07-20 22:20:59

标签: javascript php jquery html ajax

我有一个在jquery对话框中有一个文本框的表单。它工作正常,直到我使用ajax调用加载内容后,它提交textbox的值作为在ajax调用加载新内容之前提交的先前值。

无论我在文本框中输入什么内容,在完成调用后,它总是提交该文本框的先前值。我一直想弄清楚几天有什么不对,但到目前为止还没有运气。

$(document).ready(function() {

  $("#popup").dialog({
    autoOpen: false,
    title: "Popup",
    show: {
      effect: "fade",
      duration: 150
    },
    hide: {
      effect: "fade",
      duration: 150
    },

    clickOutside: true,
    clickOutsideTrigger: "#btn"
  });

  $("#btn").click(function() {
    $("#popup").dialog("open");
  });
});

$.widget("ui.dialog", $.ui.dialog, {
  options: {
    clickOutside: false,
    clickOutsideTrigger: ""
  },
  open: function() {
    var clickOutsideTriggerEl = $(this.options.clickOutsideTrigger);
    var that = this;

    if (this.options.clickOutside) {
      $(document).on("click.ui.dialogClickOutside" + that.eventNamespace, function(event) {
        if ($(event.target).closest($(clickOutsideTriggerEl)).length == 0 && $(event.target).closest($(that.uiDialog)).length == 0) {
          that.close();
        }
      });
    }
    this._super();
  },

  close: function() {
    var that = this;
    $(document).off("click.ui.dialogClickOutside" + that.eventNamespace);
    this._super();
  },
});

HTML

<button type="button" id="btn>Open Popup</button>
<div id="popup" style="display:none;">
<textarea id="textID" style="resize:none"></textarea></div>

Ajax调用

$('.link').on('click', function (e) {
    var load= $(this).attr('href');
    var $this = $(this);
    if(load == "#open") {
        $.ajax({
            type: 'post',
            url: "/page/view/" + $(this).parents("[data-id]").attr("data-id"),
            complete: function (event) {
                $("#content").contents().remove();
                $("#content").append(event.responseText);
            }
        });
    }
    });

0 个答案:

没有答案