Share:

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>


Comments

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

    website development company in Surat Gujarat

    ReplyDelete
  2. Thank you for sharing this amazing post. Looking forward to reading more.
    Best Web Design and Development Company in Delhi

    ReplyDelete

Post a Comment

Popular posts from this blog

Get Color From Pixel C# WPF | Saatody | Amit Padhiyar

Basic Audio Operations With MP3 And Wave Files Using NAudio C#

Create Drag And Drop Operation Between DevExpress GridControl And Custom WPF UI | Saatody | Amit Padhiyar