我希望能够从小页面读取信息。如何从外部URL获取JSON数据
我有一个显示以下信息的JSON服务的地址:
,我希望我可以保持显示的数字。
我测试了这个example并正常工作,但是当我尝试使用我的URL时,没有任何反应。我不知道我是否能够正确理解问题,但我希望有人能够帮助我。
如果有任何问题,我尽量做出最好的解释。
我现在问不便道歉。
,我用
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, i used it to debug
result.innerText = data.result; //display the result in an HTML element
}, function(status) { //error detection....
alert('Something went wrong.');
});
控制台中的任何错误? – phts 2015-04-01 10:45:55
假设您的请求因跨域限制而不起作用 – phts 2015-04-01 10:47:06
感谢您的回复。只是没有出现。如果我用https尝试使用错误消息。但是,如果我只用http尝试,不会给我什么。 – rpirez 2015-04-01 10:55:32