Okey, 2 개의 JSON 파일에서 데이터를 얻었습니다. 그 중 하나를 가져 와서 다른 데이터로 나누고 싶습니다. 어떻게 할 수 있습니까? 나는 'sugString'과 'htmlString'을 나누고 싶다. 그리고 내가 그 일을 한 후에 나는 이미 그것들 각각을 다뤘던 것처럼 다른 이드에 그것을 삽입하고 싶습니다.어떻게 함수 내에서 변수에 액세스 할 수 있습니까?
var flamingSkull = document.getElementById("flaming-skull");
var flamingSkullq = document.getElementById("flaming-skullq");
var flamingSkullSug = document.getElementById("flaming-skullsug");
var ourRequest = new XMLHttpRequest();
ourRequest.open('GET', 'https://api.opskins.com/IPricing/GetAllLowestListPrices/v1/?appid=433850');
ourRequest.onload = function() {
var ourData = JSON.parse(ourRequest.responseText);
renderFlamingSkull(ourData);
};
ourRequest.send();
var ourRequest2 = new XMLHttpRequest();
ourRequest2.open('GET', 'https://api.opskins.com/IPricing/GetPriceList/v1/?appid=433850');
ourRequest2.onload = function() {
var ourData2 = JSON.parse(ourRequest2.responseText);
renderFlamingSkullSug(ourData2);
};
ourRequest2.send();
function renderFlamingSkullSug(data) {
var sugString = data.response[ 'Skin: Flaming Skull Face Bandana' ][today].price/100;
flamingSkullSug.insertAdjacentHTML('beforeend', "$" + sugString);
}
function renderFlamingSkull(data) {
var htmlString = data.response[ 'Skin: Flaming Skull Face Bandana' ].price/100;
var quantityString = data.response[ 'Skin: Flaming Skull Face Bandana' ].quantity;
flamingSkull.insertAdjacentHTML('afterbegin', "$" + htmlString);
flamingSkullq.insertAdjacentHTML('beforeend', "<p>(" + quantityString + ")</p>");
}
를? – IMTheNachoMan
나는 그것의 가치를 얻고 내 페이지에 텍스트로 넣고 싶다 :) –
어디에서 코드를 원하니? 당신은 두 사람을 나누기를 원하는 두 개의 아약스 전화를합니다. – IMTheNachoMan