jquery - Parse json from an external site with JavaScript -


i trying parse json on external site having trouble. must javascript or jquery, chrome extension. point: need number external url json {"_visitor_alertsunread":"0"} , set number returned variable. how go doing this?

i have tried several things such json.parse isn't working:(

in short: how number json, on external site, , set variable?

you cannot data external url (in different domain) in javascript unless site supports jsonp or cross-origin resource sharing. if does, use xmlhttprequest data , json.parse() read it.

script:

var xhr = new xmlhttprequest(); xhr.open( 'get', 'example.com/json', true ); xhr.onload = function () { var unread = window.json.parse( xhr.responsetext )._visitor_alertsunread; }; xhr.onerror = function () { //process error }; xhr.send(); 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -