最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery ajaxForm "h is undefined" problem - Stack Overflow

programmeradmin6浏览0评论

I have a form that is brought up in a ajaxed modal which I am using for updating user details. When the modal loads I call a js function:

teamCreate: function() {
$j("#step1,form#createEditTeam").show();
$j("#step2").hide();
var options = {
 type: "get",
 dataType: 'json',
     beforeSubmit:  before,  // pre-submit callback 
     success:       success  // post-submit callback
  };
$j("form#createEditTeam").ajaxForm(options);

function before(formData, jqForm, options){ 
 var valid = $j("form#createEditTeam").valid();
 if (valid === true) {
  $j(".blockMsg").block({ message: $j('#panelLoader') });
      return true; // submit the form
 } else {
  $j("form#createEditTeam").validate();
  return false; // prevent form from submitting
 }
};

function success(data){
 if (data.status == "success") {
  $j(".blockMsg").unblock();
 } else {
  //
}
};

function error(xhr, ajaxOptions, thrownError){
alert("Error code: " + xhr.statusText);
 };
}

This works just fine when I first submit the form, regardless how many times the modal is opened and closed. However, if I submit the form and then open the modal again and try to submit the form again I get a js error:

h is undefined

I have a form that is brought up in a ajaxed modal which I am using for updating user details. When the modal loads I call a js function:

teamCreate: function() {
$j("#step1,form#createEditTeam").show();
$j("#step2").hide();
var options = {
 type: "get",
 dataType: 'json',
     beforeSubmit:  before,  // pre-submit callback 
     success:       success  // post-submit callback
  };
$j("form#createEditTeam").ajaxForm(options);

function before(formData, jqForm, options){ 
 var valid = $j("form#createEditTeam").valid();
 if (valid === true) {
  $j(".blockMsg").block({ message: $j('#panelLoader') });
      return true; // submit the form
 } else {
  $j("form#createEditTeam").validate();
  return false; // prevent form from submitting
 }
};

function success(data){
 if (data.status == "success") {
  $j(".blockMsg").unblock();
 } else {
  //
}
};

function error(xhr, ajaxOptions, thrownError){
alert("Error code: " + xhr.statusText);
 };
}

This works just fine when I first submit the form, regardless how many times the modal is opened and closed. However, if I submit the form and then open the modal again and try to submit the form again I get a js error:

h is undefined

Share Improve this question edited Mar 18, 2010 at 1:23 Simon asked Mar 18, 2010 at 1:07 SimonSimon 1,8793 gold badges23 silver badges30 bronze badges 2
  • 1 I don't see an h in your code... does the error reference a file and a line number by any chance? – Jeremy Commented Mar 18, 2010 at 1:11
  • 1 h is a variable set in the jQuery library. The line in jQuery that Firebug reports is causing the problem is: (function(b){function s(c,a){var e=c==...etHack:4};var k=null,m=[]}})(jQuery); I assume h is what jQuery is assigning as the DOM object, but I can't figure out why it is not being assigned correctly. – Simon Commented Mar 18, 2010 at 1:27
Add a ment  | 

1 Answer 1

Reset to default 6

To more quickly debug this, I would strongly suggest changing out the minified version of the JQuery library with the full version of it, then running your code again. You'd be hard-pressed to figure out the root of the problem using the minified version, but you'd most certainly find it easier to debug if you have the full version running. The variable and function names would make much more sense.

发布评论

评论列表(0)

  1. 暂无评论