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.