M
mambenanje
I am using the prototype ajax library but I realised that each time I
am calling the server for xml the new records get appended to the old
so when I display the xml data it shows the old ones and the new ones
appended. for example when i do a search on questions by calling a php
script the result will be displayed in a div area, when I make a new
search, the new results will be appended and that is all messy can
anyone help me out, I am using
// JavaScript Document
//questions model object
var Questions=Class.create();
Questions.prototype={
initialize: function(control,url){
this.control=control;
this.url=url;
this.questionsPerPage=3;
this.currentPage=0;
this.questions=[];
this.questionsXML="";
document.questionClass=this;
this.paper=new Object();
},
//get question query to server
getQuestions: function(params){
ajax=new Ajax.Request(this.url,
{
method: 'get',
parameters: params,
onComplete: this.paperLoaded
});
},
paperLoaded: function(xhr){
alert(xhr.responseText);
document.questionClass.questionsXML="";
document.questionClass.questionsXML=xhr.responseXML;
document.questionClass.extractQuestions();
document.questionClass.showQuestions();
},
//convert xml of question to array
extractQuestions: function(){
//extract paper properties
var par=this.questionsXML.getElementsByTagName('questions');
this.paper.level=par[0].getAttribute('level');
this.paper.subject=par[0].getAttribute('subject');
this.paper.year=par[0].getAttribute('year');
this.paper.paper=par[0].getAttribute('paper');
alert(this.paper.level);
//extract questions from xml cross browser purpose use get tag names
var ques=this.questionsXML.getElementsByTagName('question');
//extract all question from ques forming an object then add it to
questions array
for(i=0;i<ques.length;i++){
obj=new Object();
obj.name=ques.getAttribute('name');
obj.questionId=ques.getAttribute('questionId');
obj.question=ques.firstChild.nodeValue;
this.questions=obj;
}
my problem is with the extractquestions functions where I get the
result and output but it adds the old ones
am calling the server for xml the new records get appended to the old
so when I display the xml data it shows the old ones and the new ones
appended. for example when i do a search on questions by calling a php
script the result will be displayed in a div area, when I make a new
search, the new results will be appended and that is all messy can
anyone help me out, I am using
// JavaScript Document
//questions model object
var Questions=Class.create();
Questions.prototype={
initialize: function(control,url){
this.control=control;
this.url=url;
this.questionsPerPage=3;
this.currentPage=0;
this.questions=[];
this.questionsXML="";
document.questionClass=this;
this.paper=new Object();
},
//get question query to server
getQuestions: function(params){
ajax=new Ajax.Request(this.url,
{
method: 'get',
parameters: params,
onComplete: this.paperLoaded
});
},
paperLoaded: function(xhr){
alert(xhr.responseText);
document.questionClass.questionsXML="";
document.questionClass.questionsXML=xhr.responseXML;
document.questionClass.extractQuestions();
document.questionClass.showQuestions();
},
//convert xml of question to array
extractQuestions: function(){
//extract paper properties
var par=this.questionsXML.getElementsByTagName('questions');
this.paper.level=par[0].getAttribute('level');
this.paper.subject=par[0].getAttribute('subject');
this.paper.year=par[0].getAttribute('year');
this.paper.paper=par[0].getAttribute('paper');
alert(this.paper.level);
//extract questions from xml cross browser purpose use get tag names
var ques=this.questionsXML.getElementsByTagName('question');
//extract all question from ques forming an object then add it to
questions array
for(i=0;i<ques.length;i++){
obj=new Object();
obj.name=ques.getAttribute('name');
obj.questionId=ques.getAttribute('questionId');
obj.question=ques.firstChild.nodeValue;
this.questions=obj;
}
my problem is with the extractquestions functions where I get the
result and output but it adds the old ones