JQuery Post Simplified

0
25

 

 

Here is the most simplified JQuery POST Script with much fewer lines

Step 1 

Include JQuery

<script src=”http://code.jquery.com/jquery-1.9.1.js“></script>

Step 2 

Create your form Here is sample

<form method=”post” action=”data_post.php”>
<input name=”cust_id” id=”cust_id” type=”text” />
<input name=”name” id=”name” type=”text” />
<input name=”Button1″ id=”button1″ type=”button” value=”button” />
</form>

Here the form is posting to data_post.php but we need to do it again in the script , keep reading…

Step 3

Now the Script Part

<script>
$(document).ready(function(){
$(“#button”).click(function(){
$.post(“data_post.php”,
{
cust_id:$(‘#cust_id’).val(),
name:$(‘#name’).val()
},
function(data,status){
alert(“Data: ” + data + “\nStatus: ” + status);
});
});
});
</script>

Here what we do is calling a function on button click

$(“#button”).click(function(){}

And Next is POST , here we are Passing the entire fields which are necessary in data_post.php to process

cust_id:$(‘#cust_id’).val(),
name:$(‘#name’).val()

This will Post cust_id and name to data_post.php where we can access those by $_POST[‘cust_id’] and $_POST[‘name’]

SHARE
Previous articlecreate more twitter accounts with single email
Next articleJQuery Accordion
abhilash, is a programmer by profession and a technology addict with a passion towards browsing , shopping and imaging . My views may be biased on reviews. all images and videos are copyrighted to respective owners.

LEAVE A REPLY

Please enter your comment!
Please enter your name here