Using jquery's load method, you can easily and quickly initiate Ajax requests. You can use the load method to insert the completed text to any element contained in the package set.
Load Method syntax
Load (URL, parameters, callback) |
Parameters |
|
URL |
(String) The server resource address. |
Parameter |
(Object) parameters must be passed to the server. If this parameter is specified, the POST request is used. If this parameter is omitted, the GET request is used. |
Callback |
(Function) is called after the response data is loaded to the package set. The function parameters are text, status code, and xhr instances in sequence. |
Return Value |
Package set |
Let's look at a simple example.
ClientCode:
<HTML xmlns = "http://www.w3.org/1999/xhtml">
Main server code:
Protected void page_load (Object sender, eventargs e) {If (! Page. ispostback) {If (request ["ID"]! = NULL &&! String. isnullorempty (request ["ID"]. tostring () {response. write (getdata (request ["ID"]. tostring () ;}} protected string getdata (string ID) {string STR = string. empty; Switch (ID) {Case "1": Str + = "this is number 1"; break; Case "2": Str + = "this is number 2 "; break; Case "3": Str + = "this is number 3"; break; default: Str + = "warning other number! "; Break;} return STR ;}
RunProgram, Result
We can also deregister the post code to see the get code and get the same result.
Use httpwatcher to intercept request information. If you select a number from the drop-down list, you can intercept the following request information.
When the get method is used:
When the POST method is used:
From the two figures, we can see that when the second parameter in the load method is specified, the POST request is used, and if the second parameter is not specified, the GET request is used.
If the server returns many tags, we can further filter these tags, for example, $ ('# Show '). load ('url p'). In this way, the p tag in the returned content is selected.
Download demo