2011-12-21 2 views
0

Я использую jQuery form plugin и пытаюсь выяснить, почему я не могу использовать метод find в рамках функции успеха.Плагин формы jQuery Пробег в исходной форме

  $('#signup-form').ajaxForm({ 
      beforeSubmit: function (arr, $form, options) { 
       $form.find("input[name=email]").css('width', '170'); 
       $form.find("input[type=submit]").val('Subscribing...').attr('disabled', 'true'); 
      }, 
      target: "#signup-form-wrap", 
      dataType: 'json', 
      success: function (data, $form) { 
       $form.find("input[type=submit]").val('Go!').css('width', '200'); 

      } 
     }); 

По какой-то причине, я получаю эту ошибку:

Uncaught TypeError: Object success has no method 'find'

Когда я начеку $ форма, это значение просто строка 'успех'. Однако он работает в beforeSubmit. Что я делаю не так?

ответ

0

В соответствии с documentation вторым параметром, переданным в функцию success, является statusText, который звучит как то, что вы регистрируете. Эти параметры, передаваемые в успех-функции в соответствии с документацией:

1.) responseText or responseXML value (depending on the value of the dataType option). 
2.) statusText 
3.) xhr (or the jQuery-wrapped form element if using jQuery < 1.4) 
4.) jQuery-wrapped form element (or undefined if using jQuery < 1.4) 

Так что я предполагаю, что ваш успех функция будет что-то вроде этого:

success: function (data, status, xhr, $form) { 
    $form.find("input[type=submit]").val('Go!').css('width', '200');  
} 
+0

Это было очень быстро. Я соглашусь, когда истечет срок. Спасибо :) –

+0

@bob_cobb Мое удовольствие. Спасибо, я ценю это! –

0

Из документации JQuery Форма Plugin: http://jquery.malsup.com/form/#options-object

success

Callback function to be invoked after the form has been submitted. If a 'success' callback function is provided it is invoked after the response has been returned from the server. It is passed the following arguments:

1.) responseText or responseXML value (depending on the value of the dataType option).
2.) statusText
3.) xhr (or the jQuery-wrapped form element if using jQuery < 1.4)
4.) jQuery-wrapped form element (or undefined if using jQuery < 1.4)

Default value: null

Основываясь на этой информации, вы можете попробовать следующее:

* обратите внимание на изменения в Params направляются к успеху

$('#signup-form').ajaxForm({ 
    beforeSubmit: function (arr, $form, options) { 
    $form.find("input[name=email]").css('width', '170'); 
    $form.find("input[type=submit]").val('Subscribing...').attr('disabled', 'true'); 
    }, 
    target: "#signup-form-wrap", 
    dataType: 'json', 
    success: function (data, statusText, xhr, $form) { 
    $form.find("input[type=submit]").val('Go!').css('width', '200'); 
    } 
}); 
Смежные вопросы