Making and handling JSONP request using JavaScript

I would like to make cross domain request in the client end, so I chose JSONP. I am new to JSONP and would like to make a request to using JavaScript and not jQuery. It would be very helpful for my development if I get sample snippet to make and handle a request using JSONP in JavaScript.



Here's a small example fetching data from a google spreadsheet:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"

<html lang="en">
        //this function is the callback, it needs to be a global variable
        function readResponse(response){
            document.getElementsByTagName('SPAN')[0].innerHTML = response.feed.entry.length + ' entries returned';
            //note the "readResponse" at the end
            var src = '',
                script = document.createElement('SCRIPT');
            script.src = src;


One comment related to this example. If you want to play with your own google spreadsheet, you need to both share it as public, and publish it.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.