In jquery to implement the Ajax load method There are many kinds, unlike the previous JS Ajax only one, the following we introduce jquery AJAX implementation of local loading method summary, there is a need to understand friends can refer to.
Cases
$.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.
Instance
$ (document). Ready (function () {
function loadmessage ()
{
$ (this). html ("Loading ...");
var o = this;
var xmlhttp = $.ajax ({
URL: "service/indexlogin.aspx",
dataType: "html",
success:function (result)
{
$ (O). HTML (result);}}
);
Loadmessage.call ($ ("#addinfo"));
<form action= "#" method= "POST" >
<ul id= "Addinfo" >
loading ...
</ul>
</form>
The above is the method we use, in fact, there is a more simple way oh, the load () method to upload data from the server via AJAX request, and put the returned data into the specified element
$ (document). Ready (function () {
$ ("#addinfo"). Load ("Service/indexlogin.aspx", $ ("#addinfo li"))
1. Load a php file, the PHP file does not contain the pass parameter $ ("#myID"). Load ("test.php");
Import test.php Run results in an element with ID #myid
2. Load a PHP file that contains a pass parameter
$ ("#myID"). Load ("test.php", {"name": "Adam"});
The imported PHP file contains a pass-through parameter, similar to the following: Test.php?name=adam
3. Load a PHP file that contains multiple pass parameters. Note: The parameters are separated by commas
$ ("#myID"). Load ("test.php", {"name": "Adam", "Site": "61dh.com"});
The imported PHP file contains a pass-through parameter, similar to the following: test.php?name=adam&site=61dh.com
4. Load a php file, the php file with an array as the passing parameters
$ ("#myID"). Load ("test.php", {' myinfo[] ', ["Adam", "61dh.com"]});
The imported PHP file contains an array pass parameter.
This jquery Ajax local loading method (implementation code) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.