javascript - how to retrieve data from google book api url? -


i wan retrieve title, authors https://www.googleapis.com/books/v1/volumes?q=isbn:9780439023528 in javascript , result display in html.

html:

<p id="demo"></p> 

javascript:

    function getbookdetails(isbn) {         isbn = "9780439023528";          var url = "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn;         var response = urlfetchapp.fetch(url);         var results = json.parse(response);         if (results.totalitems) {            var book = results.items[0];            var title = (book["volumeinfo"]["title"]);            document.getelementbyid("demo").innerhtml = book;         }        } }); 

urlfetchapp class not available in client-side javascript, looks trying do. can use in server-side google apps script .gs files.

you can use xmlhttprequest fix problem.

function getbookdetails(isbn) {     isbn = "9780439023528";      var xmlhttp = new xmlhttprequest();     var url = "https://www.googleapis.com/books/v1/volumes?q=isbn:" + isbn;      xmlhttp.onreadystatechange = function() {         if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {             var x = json.parse(xmlhttp.responsetext);             callback(x);         }     };     xmlhttp.open("get", url, true);     xmlhttp.send(); } function callback(x) {     //do things data here     console.log(x); } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -