简体   繁体   中英

Ajax: onload serialize() form

I want to submit form data with ajax "onload".

Does the following jquery-ajax submit its data on load? If not how to do it?

<form method="GET" name="myform2" id="myform2">
<input type="hidden" name="car" value="bmw">
<input type="hidden" name="moto" value="honda">
<button id="submit2" type="submit" value="submit2" name="submit2">

Js

            $(document).ready(function(){      
            function sssssss2(page){
            var form2 = document.myform2;
            var dataString1 = $(form2).serialize() + '&page=' + page;
                $.ajax
                ({
                    type: "GET",
                    url: "query.php",
                    data: dataString1,
                    success: function(ccc)
                    {
                     $("#search_results").html(ccc);
                    }
                });
            }
            sssssss2(1) ;
            $('#search_results .pagination li.active').live('click',function(){
                var page = $(this).attr('p');
                sssssss2(page);                 
            });  
            });

Both document ready and window load both occur roughly at the same time.

But you can also write like this

$(window).load(function() {
      // your code here
});

This function will execute when window is loaded fully. and yes use .on inspite of .live().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM