JQuery Ajax method Loads page local content

Source: Internet
Author: User

The AJAX approach to using jquery can easily help us complete AJAX operations, but this method returns the HTML of the entire page, which is very unfriendly if you add an entire page of HTML append to the page, which is a good way to solve the problem.

The code is as follows Copy Code

$.ajax ({
URL: "Hotelquery!queryhotelbycity.action",
Type: "Post",
DataType: "HTML",
Data: "queryhotel.city=" +cityobj.value+ "&queryhotel.wbcid=" +wbcid,
Success:function (data) {
$ ("#hotellists"). HTML ($ (data). Filter ("#list"). html ();
}
});

Code resolution:

From the code above, we can see that the data returned is, but if we enclose a div with ID list in the part of the page where the AJAX request is made, we pass $ (data). Filter ("#list"). HTML () You can get the HTML content in the Div, which is what we want.

An easier way for individuals is to use load () to manipulate

Load full format is: Load (URL, [Data], [Callback])

URL: Web page path (in this case, only in the same directory can be used, other external pages will not work)

Data: Parameters

Callback: Functions


URL path

The code is as follows Copy Code

$ (' #div1 '). Load ("load.aspx"); The contents of the load.htm are displayed on the DVI1 surface.

Data parameter

The code is as follows Copy Code

$ (' #div1 '). Load ("load.aspx", {"id": "1"}); As load.aspx?id=1.

$ (' #div1 '). Load ("load.aspx", {"id": "1", "page": "1"}); As load.aspx?id=1&page=1.

callback function

Refers to the load completed action (CallBack)

The code is as follows Copy Code

$ (' #div1). Load ("load.aspx", {"id": "1", "page": "1"}, function () {alert ("load Complete");});

Selector Selector

The code is as follows Copy Code
$ (' #div1 '). Load ("load.aspx #img1");

 //refers to loading only the Load.aspx ID?? A Mg1 object.

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.