0

私はjQueryフォームプラグインを使用していて、success関数内でfindメソッドを使用できない理由を理解しようとしています。

           $('#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'

$ formに警告すると、その値は文字列「success」にすぎません。ただし、beforeSubmitでは機能します。私は何が間違っているのですか?

4

2 に答える 2

0

jQueryフォームプラグインのドキュメントから:http://jquery.malsup.com/form/#options-object

成功

フォームの送信後に呼び出されるコールバック関数。'success'コールバック関数が提供されている場合、サーバーから応答が返された後に呼び出されます。次の引数が渡されます。

1.)responseTextまたはresponseXML値(dataTypeオプションの値によって異なります)。
2.)statusText
3.)xhr(またはjQuery <1.4を使用している場合はjQueryでラップされたフォーム要素)
4。)jQueryでラップされたフォーム要素(またはjQuery <1.4を使用している場合は未定義)

デフォルト値:null

その情報に基づいて、次のことを試してみてください。

*成功するために送信されるパラメータの変更に注意してください

$('#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');
  }
});
于 2011-12-21T21:20:34.473 に答える
0

ドキュメントによると、success-functionに渡される2番目のパラメーターはstatusTextであり、これはログに記録しているもののように聞こえます。ドキュメントに従って、success-functionに渡されるパラメーターは次のとおりです。

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');    
}
于 2011-12-21T21:18:00.743 に答える