私は問題に直面しています。私がhttp://headers.jsontest.com/
を使うとき、私は価値を得る。ここに私のコードjavascriptでjson形式の配列からデータを取得する方法
<div id="ip"></div>
<script type="text/javascript">
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://headers.jsontest.com/').then(function(data) {
for(x in data){
ip.innerText = data.Host;
}
}, function(status) {
alert('Something went wrong.');
});
</script>
あるしかし、私は、このリンクを使用するとき、私は任意の値My Linkを得ることはありません。それは、デフォルトのデータ・フォーマット{data}
場合
getJSON('http://67.225.137.209/index.php/queue_manage_api/queue/doc_id/3536/loc_id/4696/username/9791a47fef07649b1c3e70749e898153/password/2d593e25d0560b19fd84704f0bd24049/format/json').then(function(data) {
for(x in data){
ip.innerText = data.id;
}
}, function(status) {
alert('Something went wrong.');
});
を働いていないのはなぜ、私は、デフォルト値を取得する。しかし[{data}]
のようなデータ形式は、私はまた、任意の値を取得していない場合。私のデータフォーマットは[{data}]
です。だから私のデータを取得する方法
コンソールを確認しますか?何か間違いはありますか? – mehulmpt
$ .getJSON( "http://67.225.137.209/index.php/queue_manage_api/queue/doc_id/3536/loc_id/4696/username/9791a47fef07649b1c3e70749e898153/password/2d593e25d0560b19fd84704f0bd24049/format/json") –
data.Hostが設定されていません使用しているデータに –