-3

jquery/AJAX 検証システムの一部として、次の jQuery コード スニペットを継承しました。スクリプトのいくつかのアクションを変更する方法を理解できるように、コメントを付けてコードを1行ずつ説明してくれる人が必要です。

// Use Ajax to send everything to form processing file
submitHandler: function(form) {
    $("#send").attr("value", "Sending...");
    $(form).ajaxSubmit({
        success: function(responseText, statusText, xhr, $form) {
            $(form).slideUp("slow");
        $("#response").html(responseText).hide().slideDown("slow");
        }
    });
    return false;
}

具体的には、行 re 'success . . . $(form).slideUp("slow") がフォームをゆっくりとスライドさせることがわかるので、私にとって特に興味深いものです (ちょっと明白ですよね?)。「slideUP」アクションでは、フォームの先頭には移動しませんが、常にフォームの途中に移動します。jQuery をもう少しよく理解できれば、「slideUp」で常にフォームの先頭に移動する方法がわかるかもしれません。

4

2 に答える 2

4

この関数は、要素のsubmitイベントを処理するために使用されます。form

submitHandler: function(form) {

送信ボタンをクリックすると、値SendがSending...に変わります。

    $("#send").attr("value", "Sending...");

この関数ajaxSubmitは、ページを更新せずにフォームを別の URL に送信します。

    $(form).ajaxSubmit({

送信後、この関数が呼び出されます。responseTextはサーバーから返されるテキストです。statusTextHTTP ステータス コードです。xhr使用するXMLHttpRequestオブジェクトです。$form処理されたform要素です。

        success: function(responseText, statusText, xhr, $form) {

form送信後、アニメーションで上にスライドします。

            $(form).slideUp("slow");

#response滑らかに下にスライドすることで、ユーザーに情報を表示する場所である divを埋めています。

        $("#response").html(responseText).hide().slideDown("slow");
        }
    });

通常の HTTP 送信からフォームを停止しています。

    return false;
}
于 2012-09-05T19:32:17.883 に答える
1

私のナラティブノートは//#

// Use Ajax to send everything to form processing file

//# Create a function called 'submitHandler'
submitHandler: function(form) {

    //# Set a form field saying the form is being sent.
    $("#send").attr("value", "Sending...");

    //# Using the form, sumit its value using jQuery's ajaaax
    $(form).ajaxSubmit({

        //# Should the result be successful, call this function
        success: function(responseText, statusText, xhr, $form) {
            //# Slide the form into view (I believe)
            $(form).slideUp("slow");
            //# This puts the return value of the AJAX caall into #response
            $("#response").html(responseText).hide().slideDown("slow");
        }
    });

    //# I'm pretty sure that under jQuery this will stop the default action,
    //# which would be a regular form submit.
    return false;
}
于 2012-09-05T19:31:56.970 に答える