Wednesday, February 9, 2011

How to make a form post request in jQuery

Download the latest jQuery http://code.jquery.com/jquery-1.4.4.min.js save that in your server, set it as your source file, then call the method $.ajax() with parameters as follows:
  • URL as your form action
  • TYPE as your form method
  • DATA as your input parameters.
You can also set the callback function for successful and error transactions.

<script type="text/javascript" src="http://domain.url.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
        function form_post() {
                $.ajax({
                        url : 'http://domain.url.com/form.php',
                        type: 'post',
                        data: {'param1' : 'param1_value', 'param2' : 'param2_value'},
                        success: function(data){
                                alert(data);
                        },
                        error: function(data){
                                alert(data);
                        }
                });
        }
</script>

No comments:

Post a Comment