prototype problem

Discussion in 'Javascript' started by mambenanje@gmail.com, May 15, 2006.

  1. Guest

    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
    , May 15, 2006
    #1
    1. Advertising

  2. wrote:

    > I am using the prototype ajax library [...]


    Prototype.js is junk; please do not ask about it here. It is only
    a pity that one cannot filter out all postings with a Subject header
    containing "prototype". Because the languages discussed use a
    prototype-based object model -- one that Prototype.js ignores,
    despite its name.


    PointedEars
    Thomas 'PointedEars' Lahn, May 22, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. June Lee
    Replies:
    2
    Views:
    800
    Jim Cobban
    Apr 13, 2008
  2. Christopher Benson-Manica

    Date prototype problem

    Christopher Benson-Manica, Jun 13, 2005, in forum: Javascript
    Replies:
    7
    Views:
    126
    Thomas 'PointedEars' Lahn
    Jun 26, 2005
  3. Replies:
    9
    Views:
    186
    Thomas 'PointedEars' Lahn
    May 26, 2006
  4. Replies:
    3
    Views:
    264
  5. javascript fish
    Replies:
    0
    Views:
    168
    javascript fish
    Oct 11, 2008
Loading...

Share This Page