1

Web サイトのすべてを div 内にロードしたいので、フォーム送信を処理してアクションを同じ div にロードする関数を作成しましたが、問題はaction=""、スクリプトが同じページにあるため、一部のフォームにアクションがないことです、フォームを送信してもdiv内では何も起こらないので、関数でこれを処理するにはどうすればよいですか?

$(document).ready(function() {
              $('#mydiv').delegate('form', 'submit', function() { // catch the form's submit events inside the div
    $.ajax({ // create an AJAX call...
        data: $(this).serialize(), // get the form data
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
        success: function(response) { // on success..
             //$('#mydiv').html(response); // update the DIV
            $('#mydiv').fadeOut('slow',function() {
                        $('#collabsoft').html(response).fadeIn('slow');
                });
              //  return false;
}
    });
4

1 に答える 1

1

三項 if ステートメントを使用できます。

url: $(this).attr('action') == '' ? window.location : $(this).attr('action')
于 2012-05-13T03:26:10.077 に答える