Read Blogger Feeds Using AJAX Callback Function - Amit Padhiyar (Saatody)
This article is all about read AJAX callback function. This callback function gives output in XML and JSON formats. This will also help us to make blogger widgets without blogger tags like <b:widget>.
The callback function read blogger feeds using readJSON() and readXML() functions. Write entire program between <script> tag.
<script>
</script>
Create callback function in AJAX
function read(_url, _function){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
_function(this);
}
};
xhttp.open('GET',_url,true);
xhttp.send();
}
Create callback function for JSON format
function readJSON(_url, _function){
read(_url + "?alt=json", _function);
}
Create callback function for XML format
function readXML(_url, _function){
read(_url ,_function);
}
Create function that write output in browser console
function writeInConsole(xhttp){
var data = xhttp.responseText;
console.log(data);
}
Call functions and get output in browser console
readJSON("https://demo.blogspot.com/feeds/posts/default",writeInConsole);
readXML("https://demo.blogspot.com/feeds/posts/default",writeInConsole);
Look at entire script
<script>
function read(_url, _function){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
_function(this);
}
};
xhttp.open('GET',_url,true);
xhttp.send();
}
function readJSON(_url, _function){
read(_url + "?alt=json", _function);
}
function readXML(_url, _function){
read(_url ,_function);
}
function writeInConsole(xhttp){
var data = xhttp.responseText;
console.log(data);
}
readJSON("https://demo.blogspot.com/feeds/posts/default", writeInConsole);
readXML("https://demo.blogspot.com/feeds/posts/default", writeInConsole);
</script>
This article is a great article that I have seen in my blog career so far, it helps me a lot in ajax coding, and will continue to do so in the future.
ReplyDeletewebsite development company in Surat Gujarat
Thank you very much!
DeleteThank you for sharing this amazing post. Looking forward to reading more.
ReplyDeleteBest Web Design and Development Company in Delhi