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.
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.