我有下一個js代碼。如何使用javascript/jquery打印數據
var myData=[];
for(j=1;j<=Pages;j++)
{
$.ajax({
type: 'get',
url: 'link.xml'+j,
async: false,
dataType: 'xml',
success: function(data){
getData(data);
},
error: function(data){
console.log("error");
}
});
}
function getData(data){
var tmpData = {id:'' , displayName:''};
//taking the values and storing them to myData
myData.push(tmpData);
tmpData = {id:'' , displayName:'', eventsHref: []};
}
for(i=0;i<myData.length;i++)
{
$.ajax({
type: 'get',
url: 'somelink'+data[i].id,
async: false,
dataType: 'xml',
success: function(events){
getUpEvents(events);
},
error: function(events){
console.log("error");
}
});
}
function getUpEvents(events){
var tmpEvents = {displayNameEvent:[] , displayNameArtist: []};
//taking some other values and storing them to myData
myData.push(tmpEvents);
tmpEvents = {displayNameEvent:[] , displayNameArtist:[]};
}
我們瞭解myData的與特定的打印結果way.In第一行myData的[0] .displayName.Next線路中的全部myData的[I] .displayNameEvents指示到myData的[0] .displayName和所有myData [i] .displayNameArtist.After後,它將打印下一個myData [1] .displayName,繼續。
以下是我如何打印它們。
for(i=0;i<myData.length;i++)
{
document.write(myData[i].displayName+"<br>");
document.write(myData[i].displayNameEvent+"<br>");
document.write(myData[i].displayNameArtist+"<br>");
}
不要使用'document.write' - http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice – Halcyon