There is a method in Jqery that $.post () makes a simple example of this method:
Jquery.post (URL, [data], [callback], [type]):
Use post to make asynchronous requests
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>untitled document</title>
<script type= "Text/javascript" src=\ ' #\ ' "/jquery-1.3.2.js" ></script>
<script language= "JavaScript" >
function Checkemail () {
if ($ (' #email '). val () = = "") {
$ (' #msg '). HTML ("Please enter the email!");
$ (' #email '). Focus;
return false;
}
if ($ (' #address '). val () = = "") {
$ (' #msg '). HTML ("Please enter the address!");
$ (' #address '). Focus;
return false;
}
Ajax_post ();
}
function Ajax_post () {
$.post ("action.php", {email:$ (' #email '). Val (), address:$ (' # Address '). Val ()},
function (data) {
//$ (' #msg '). HTML ("Please enter the email!");
//alert (data);
$ (' #msg '). HTML (data);
},
"text");//The type returned here is: Json,html,xml,text
}
</script>
<body>
<form id= "Ajaxform" name= "Ajaxform" method= "post" action= "action.php" >
<p>
Email<input type= "text" name= "email" id= "email"/>
</p>
<p>
Address<input type= "text" name= "Address" id= "Address"/>
</p>
<p id= "MSG" ></p>
<p>
<input name= "Submit" type= "button" value= "Submit" onclick= "return Checkemail ()"/>
</p>
</form>
</body>
2.php page (action.php)
Copy CodeThe code is as follows:
<?php
$email = $_post["email"];
$address = $_post["Address"];
Echo $email;
Echo $address;
echo "Success";
?>
Note : When you click the button, notice that the button is now the type is button. When you do not use the $.post () method, the button type is submit, so that submit submits the data in the form, using the Post method to pass to the page action.php, At this point in the page action.php can receive the data sent. When using the $.post method, we actually use the Post method in the function Ajax_post () method. (To reference the jquery library file)
A simple example of the $.post () method in jquery