Post is a data submission mode in jquery ajax and is the same as the post method in the form. Let's take a look at a simple ajax post learning note.
Use jQuery to obtain AJAX asynchronous data. The following example shows the AJAX function similar to a user name.
JQuery. post (url, [data], [callback], [type]):Use POST for asynchronous requests
Parameters:
Url (String): the URL of the request.
Data (Map): (optional) data to be sent to the server, expressed in Key/value pairs.
Callback (Function): (optional) callback Function when the load is successful (this method is called only when the Response returns success ).
Type (String): (optional) the official description is: Type of data to be sent. In fact, it should be the client request type (JSON, XML, and so on)
This is a simple POST Request function to replace complex $. ajax. You can call the callback function when the request is successful. To execute a function when an error occurs, use $. ajax. Sample Code:
JS Code
The Code is as follows: |
Copy code |
<Script> $ (Document). ready (function (){ $ (". Ajax_btn"). click (function (){ $. Post ("ajax. php", // process dynamic pages Asynchronously {Name: $ (". name"). val ()}, // gets the value of the text class named "name" and asynchronously transmits the value by NAME Function (data) {// data is the reverse return value, and the function performs the reverse return value processing. $ (". Content"). val (data); // enter the reversed value in the text box named "content ". }); }) }) </Script> |
Ajax. php code
The Code is as follows: |
Copy code |
<? Php $ Name = $ _ POST ["name"]; If ($ name = "netxu "){ Echo "sorry,". $ name. "data exists "; } Else { Echo "congratulations,". $ name. "available "; } ?> |
HTML code
The Code is as follows: |
Copy code |
<P> the page effect is as follows: (when you enter <a href = "http://www.hzhuti.com" title = "thoughts"> netxu </a>, a message is displayed, if you enter other information, the system prompts that the data is available.) </p> <P> pass value text: <input type = "text" class = "name" size = "20" value = "netxu"/> </p> <P> asynchronous reception: <input type = "text" class = "content" size = "20" style = "color: # F00 "/> <input type =" button "class =" ajax_btn "value =" Asynchronous processing "/> </p> |
The same is true for ASP, but the output format is different.