I am trying to reload a JSON file with jquery every 10 seconds.
This page is here:
The code is here:
& lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Title & lt; / Title & gt; & Lt ;! - Included Jquery Library - & gt; & Lt; Script type = "text / javascript" src = "./ js / jquery-1.4.2.js" & gt; & Lt; / Script & gt; & Lt ;! - jquery library - & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Script & gt; $ .ajaxSetup ({cache: false}); // caching is not allowed, so the information should be loadChirp () new function (// start function var url = "http://www.chirpradio.org/json"; $ .getJSON ("http: // query .yahooapis.com / v1 / public / yql? Q = select% 20 *% 20from% 20json% 20where% 20url% 3D% 22 "+ url +"% 22and format = json & callback =? ", Function (data) {console.log (data.query.results.json); document.write ('artist:' + data.query.results.json.artist + '
;); document.write ('artist:' + data.query.results.json ["record label"] + '
); Document.write ('album is:' + data.query.results.json.album + '
document.write (' record label '+ Data.query.results.json ["record-label"]' '
document.write (' feedback link is: '+ Data.query.results.json ["feedback-link"] + '
document.write (' database id is: '+ data.query. Results.json [database-id "] + '& lt; Br / & gt; & Lt; Br / & gt; '); Document.write ('time is:' + data .query.results.json.timestamp.time + ''); Document.write (data.query.results.json.timestamp ["am-pm"] ''
Document.write ('The current DJ is:' + data.query.results.json ["current-DJ"] + '
SetTimeout ("loadChirp ()", 5000); Warning ('time was out.'); }); } // end function $ (document) .ready (function () {// document ready function loadChirp ();}); // Document ready work & lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;
This is not working.
You probably want the previous set of data replaced with the new set, instead of adding it. In that case, you can use jQuery:
& lt; Div id = 'content' & gt; & Lt; / Div & gt; & Lt; Script & gt; Function Load Printer () {$ .getJSON ("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22" + url + "% 22 & amp;; Format = json & amp; callback =? & Quot;, function (data) {$ ('# content') .HTML ('artist:' + data.query.results.json.artist + '& lt ; Br / & gt; & lt; br / & gt; ';)}); SetTimeout ("loadChirp ()", 5000); } & Lt; / Script & gt;
etc ...
Comments
Post a Comment