Post a form field using jquery

Step: 1 Create a Form

<form id=”Test_form”>

Name:<input type=”text” name=”name” onsubmit=””>

Age:<input type=”text” name=”name”><br>

<div id=”result”></div>

<input type=”submit” value=”Submit” />

</form>

Step: 2 Now javascript code

<script type=”text/javascript”>

function send()

{

$.ajax({type:’POST’, url:’path_file_processing’, data:$(“#form_id”).serialize(), success:function(response){alert(response);}});

}

</script>

It will perfectly

3 thoughts on “Post a form field using jquery

  1. Hi Rakesh,
    For jQuery ajax calls, there’s a rather nice shorthand you can use, as well.

    $.ajax({type:’POST’, url:’path_file_processing’, data:$(“#form_id”).serialize(), success:function(response){alert(response);}});

    is equivalent to:

    $.post(‘path_file_processing’, $(“#form_id”).serialize(), function(r){ alert(r); });

    I hope that saves your keyboard some strain. Happy coding.

Leave a comment