There is a method in Jqery, $.post () to do a simple example of this method:
Jquery.post (URL, [data], [callback], [type]):
Use post to make asynchronous requests
Parameters:
URL (String): The URL address where the request is sent.
data (MAP): Optionally, the data to be sent to the server is represented in the form of a Key/value key value.
Callback (Function): Optionally, the callback function (which is invoked only when the response return state is success) is loaded successfully.
type (String): (optional) The official note is: Type of data to be sent. The type that should actually be requested for the client (Json,xml, etc.)
1.html page (index.html)
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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 types returned here are: 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 Code code as follows:
<?php
$email = $_post["email"];
$address = $_post["Address"];
Echo $email;
Echo $address;
echo "Success";
?>
Description:When you click on the button, note that the button is now in the type buttons. When you do not use the $.post () method, the button type is submit, so submit the data in the form, and pass the Post method to the page action.php. At this point in the page action.php can accept the data passed over. When using the $.post method, we actually use the Post method in the function Ajax_post () method. (to refer to the jquery library file)