How can I access form POST data from jQuery .submi

2019-09-13 17:19发布

问题:

I need to access a hidden field named 'partnerId' in my form data from this js code:

$(document).ready(function() {
  showPartnerSettings = function(e) {
    e.preventDefault();

    var $dialogForm = $("<div />")
    .attr("id", "partner-settings-form")
    .append($loading.clone())
    .load(envPath + "/partner/settings?partnerid="+e.data.partnerId, null, function(){ $("#partner-settings-form").css("display", "block"); })
    .dialog({
      title: "Partner Settings",
      modal: false, 
      resizable: false,
      width: 580, //CPB 04.11.13
      position:['middle',130],
      "close" : function(){ 
        var dialogid=$(this).parent("div").attr("id");
        $("#Tabs ul li."+dialogid).remove();
        $(this).remove();
        $("#alertmod").remove();
        //$link.removeClass('preventclick');
      },
    })        
    .dialog("open")
    .css("display", "block");

    return false;
  };

Is there any way to retrieve this value from the event object passed to showPartnerSettings()?

回答1:

You're going to need to access it after it has been loaded into the DOM.

var $dialogForm = $("<div />")
    .attr("id", "partner-settings-form")
    .append($loading.clone())
    .load(envPath + "/partner/settings?partnerid="+e.data.partnerId,
          null,
          function(){
              /* access field here ... */
              var field = $('#partnerId');

              $("#partner-settings-form").css("display", "block");
          }
     ).dialog({
      title: "Partner Settings",
      modal: false, 
      resizable: false,
      width: 580, //CPB 04.11.13
      position:['middle',130],
      "close" : function(){ 
        var dialogid=$(this).parent("div").attr("id");
        $("#Tabs ul li."+dialogid).remove();
        $(this).remove();
        $("#alertmod").remove();
        //$link.removeClass('preventclick');
      },
    })        
    .dialog("open")
    .css("display", "block");