简体   繁体   中英

Jquery Success concept

I am trying to work with Jquery .ajax {type: get} and I am having trouble figuring out how the success function works, the documentation just isn't cutting it for me.

  1. When I .ajax{get} page.php what code does it grab from page.php
  2. What is the variable/function you use, in Jquery, to get the GET data (I'm thinking in terms of PHP $_get)
  3. When I GET the data from page.php it will be in full HTML format and ready to be applied to the page. All I need it to do is be posted underneath existing data. Would I use the .appendto() on the DIV I want the html content pasted into?

Also do you guys know any good Jquery books? Somehow I just know I will be using this all of the time and I might as well learn it too.

The proper syntax of the Ajax is as following:

 jQuery.ajax({
           url: "", //here you need to give the full path of the URL.
           cache: true/false, //choose any one true if you want to enable the cache.
           type: "get/post", // any type which you want to choose to post the data.
           dataType: "text/html/json/jsonp/xml", //In your case choose the html.
           success: function(returnData){
               //here the returnData will be data that you print in file given in URL. 
               alert(returnData);
               $(".someDiv").append(returnData); //To answer #3
           },
           error: function(a,b,c){
               //call when any error occur.
           }
    });

I hope this will be helpful to you.

In the success function

$.ajax({ success : function(retrunValues) { alert( retrunValues); } });

you can get any data from you backend page . like result of any query or any thing check this .

backendpage.php
<?php

echo "this data will be printed on the main page with ajax call";

?>

so this data from php page will be in the retrunValue of the success function .Then you can use it how you like to use it .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM