Vincent
Vincent

Reputation: 61

Ajax with jQuery, submit handler

I still need your help. Today, I would like to develop a small feature in Ajax with jQuery.

I found a simple tutorial, which answers my wish. Author uses Jquery Validate Plugin, I do not need.

I don't know how to translate the code without the use this plugin. I tried dozens of combinations (I'm not very gifted!).

Here is original code...

<script type="text/javascript">
$(document).ready(function(){
    $("#myform").validate({
        debug: false,
        rules: {
        ///
        },
        messages: {
        ///
        },
        submitHandler: function(form) { // How to repace this?
            $.post('process.php', $("#myform").serialize(), function(data) {
                $('#results').html(data);
            });
        }
    });
});
</script>

Thanks for your help. :)

Regards,

Vincent

Upvotes: 0

Views: 6263

Answers (4)

Joberror
Joberror

Reputation: 5890

Please always navigate here for more info

http://api.jquery.com/jQuery.ajax/

Upvotes: 0

DKSan
DKSan

Reputation: 4197

Well,

what about just sending your data to the server and waiting for the answer?

$.ajax({
   url: '/your_script_url',
   data: ({data_1 : "data_1", data_n : "data_n"}),
   success: function(data) { do something; } } );

I hope this will help you.

Upvotes: 0

benhowdle89
benhowdle89

Reputation: 37464

var data = $("#myForm").serialize();
$.ajax
                            ({
                            type: "POST",
                            url: "mail.php",
                            data: data,
                            cache: false,
                            success: function()
                                {
                                    alert("Thank you");
                                }
                            });

This is the basic premise for AJAX with jQuery - you should be able to sub in your code with this easily :)

Upvotes: 0

David Tang
David Tang

Reputation: 93664

Check out .submit():

$(document).ready(function(){
    $("#myform").submit(function(e) {
        e.preventDefault();

        // This part stays the same
        $.post('process.php', $("#myform").serialize(), function(data) {
            $('#results').html(data);
        });
    });
});

... Which binds an event handler to the submit event of your form. e.preventDefault then prevents the form from being submitted normally (without ajax).

Upvotes: 6

Related Questions