Use of Ajax request Load Method

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.