phpを使用してIDで情報をランダム化し、xml経由で送信しているデータベースがあります。私の問題は、xmlを1回だけ取得し、少なくとも2つの関数で使用するために保存したいということです... 1つの関数はonloadを実行してxmlの最初の行を取得し、もう1つはボタンを押してアクセスするたびに実行します最後までxmlの次の行。私の2つの関数はloadfirst()とloadnext()です。loadfirst()は完全に機能しますが、xmlデータをloadnext()に渡す方法がわかりません。現在、pageloadでloadfirst()を使用し、ボタンを押すとloadfirst()を使用していますが、データベースから毎回新しいxmlを作成することになり、ランダム化の問題が発生し、非常に非効率的です。どんな助けでもいただければ幸いです。
var places;
var i = 0;
function loadXML(){
downloadUrl("places.php", function(data){
places = data.responseXML;
getFeatured(i);
});
}
function getFeatured(index){
var id = places[index].getAttribute("id");
var name = places[index].getAttribute("name");
var location = places[index].getAttribute("location");
var imgpath = places[index].getAttribute("imgpath");
var tags = places[index].getAttribute("tags");
}
function getPrev() {
i--;
getFeatured(i);
}
function getNext() {
i++;
getFeatured(i);
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
loadnext()はloadfirst()と非常によく似ていますが、データベースに再度アクセスしなくても使用できるように、xmlデータの受け渡しで問題が発生しています。ありがとう。