jquery Ajax Local Loading method detailed (Implementation code) _jquery

Source: Internet
Author: User

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.

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.