Introduction to jquery Ajax Local loading method

Source: Internet
Author: User
Tags php file


Cases

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.

Instance

The code is as follows Copy Code

$ (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" >
In load ...
</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

The code is as follows Copy Code

$ (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

The code is as follows Copy Code

$ ("#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

The code is as follows Copy Code

$ ("#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

The code is as follows Copy Code

$ ("#myID"). Load ("test.php", {' myinfo[] ', ["Adam", "61dh.com"]});

The imported PHP file contains an array pass parameter.

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.