javascript - How get JSON data from external URL -


i able read information small page.

i have address of json service displays following information:

enter image description here

and wish keep number appears.

i tested example , work correctly, when try url nothing happens. not know if understand problem correctly, wish please me.

if have questions, try explain best possible.

i ask apologize inconvenience.

the code used

var getjson = function(url) {   return new promise(function(resolve, reject) {     var xhr = new xmlhttprequest();     xhr.open('get', url, true);     xhr.responsetype = 'json';     xhr.onload = function() {       var status = xhr.status;       if (status == 200) {         resolve(xhr.response);       } else {         reject(status);       }     };     xhr.send();   }); };  getjson('http://myaddress/json.do?_uln[1]').then(function(data) {     alert('your json result is:  ' + data.result); //you can comment this, used debug      result.innertext = data.result; //display result in html element }, function(status) { //error detection....   alert('something went wrong.'); }); 

you can't security reasons. see same origin policy javascript.

there workarounds exploit browser bugs or corner cases, using them not recommended.

the best approach having server-side proxy receives ajax requests, , in turn, sends http requests other servers. should implemented sanitizing input , whitelisting types of requests sent, , servers contacted.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -