Home > Web Front-end > JS Tutorial > body text

Simple example of $.post() method in jquery_jquery

WBOY
Release: 2016-05-16 17:01:31
Original
1230 people have browsed it

There is such a method in jqery, $.post() Here is a simple example of this method:

jQuery.post( url, [data], [callback], [type] ):
Use POST method to make asynchronous requests

Parameters:

url (String): The URL address to send the request.

data (Map) : (optional) The data to be sent to the server, expressed in the form of Key/value pairs.

callback (Function) : (optional) Callback function when loading is successful (this method is called only when the return status of Response is success).

type (String) : (Optional) The official description is: Type of data to be sent. In fact, it should be the type requested by the client (JSON, XML, etc.)

1.html page (index.html)

Copy code The code is as follows:





Untitled Document





email



  address




  






2.php page (action.php)
Copy code The code is as follows:

$email = $_POST["email"];
$address = $_POST["address"] ;

//echo $email;
//echo $address;
echo "success";
?>


Description: When you click the button, note that the current type of the button is button. When the $.post() method is not used, the button type is submit. In this way, submit submits the data in the form and uses the post method to pass it to the page action. php, then the passed data can be received in the page action.php. When using the $.post method, we actually use the post method in the function ajax_post() method. (To quote the jquery library file)
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template