Little Problem in Spy.Please help me...

Discussion in 'C#' started by pushkar, Dec 17, 2006.

  1. #1
    Hello Guys.
    I have made spy(Like DP) in ASP successfully but now i have problem that spy start success but when any new entry is done in the database there is no updation in spy.
    why this hepen i dont know.

    My js code is as below.

    var auctionmax;
    var play = 1;
    var bidids = new Array(0);
    var itemnames = new Array(0);
    var itemvalues = new Array(0);
    var unames = new Array(0);
    var bidvalues = new Array(0);
    var biddates = new Array(0);
    var lastpushbidid = 0;
    var flag = 0;
    function init() {
            getXML();
    }
    
    function pauseAuction() {
            var playimg = document.getElementById("auctionStart");
            var pauseimg = document.getElementById("auctionPause");
    
            playimg.src = "/images/play_up.gif";
            playimg.alt = "Click to Play";
            pauseimg.src = "/images/pause_down.gif";
            pauseimg.alt = "Paused...";
            
            pause();
    }
            
    function playAuction() {
            var playimg = document.getElementById("auctionStart");
            var pauseimg = document.getElementById("auctionPause");
    
            playimg.src = "/images/play_down.gif";
            playimg.alt = "Playing...";
            pauseimg.src = "/images/pause_up.gif";
            pauseimg.alt = "Click to Pause";
            
            resume();
    }
            
    function pause() {
            play = 0;               
    }       
    
    function resume() {
            play = 1;
    }
    
    var notimes=0;
    function getXML() {
             var url = "/auction/auctionlive.asp";
            var querystring = "limit=" + auctionmax + "&rnd=" + Math.random();
            var myAjax = null;     
    
    
            myAjax = new Ajax.Request(
               url,
                {
                        method: 'get',
                            asynchronous: true,
                            parameters: querystring,
                            onComplete: processXML
            });
    }
    
    function processXML(request) {
            var auctions;
            var auction;
            try {
                     auctions = request.responseXML.getElementsByTagName("auctions")[0];
                     auction = auctions.getElementsByTagName("auction");
             }
            catch (e) {
                    setTimeout("getXML()", 10000);
                    return;
            }
            
            
           for (i = 0; i < auction.length; i++) {
           
                    try {
                            bidids[i] = auction[i].getElementsByTagName("bidid")[0].firstChild.nodeValue;
                    }
                    catch (e) {
                            bidids[i] = "Unknown ID";
                    }
     
     
                     try {
                            itemnames[i] = auction[i].getElementsByTagName("itemname")[0].firstChild.nodeValue;
                    }
                    catch (e) {
                            itemnames[i] = "Untitled";
                    } 
                    try {
                            itemvalues[i] = auction[i].getElementsByTagName("itemvalue")[0].firstChild.nodeValue;
                            
                    }
                    catch (e) {
                            itemvalues[i] = "Random";
                    }
                     
                    try {
                            unames[i] = auction[i].getElementsByTagName("username")[0].firstChild.nodeValue;
                    }
                    catch (e) {
                            unames[i] = "Anonymous";
                    }
                    try {
                            bidvalues[i] = auction[i].getElementsByTagName("bidvalue")[0].firstChild.nodeValue;
                    }
                    catch (e) {
                            bidvalues[i] = "Guess";
                    }
                     
                    try {
                            biddates[i] = auction[i].getElementsByTagName("biddate")[0].firstChild.nodeValue;
                    }
                    catch (e) {
                            biddates[i] = "Any Date";
                    }
                
              }      
    //          "Refresh time: " +  notimes + " last push id is " + lastpushbidid +" and no of auctions this times are " + auction.length-1;
    document.getElementById("notimes").innerHTML =auction.length  ; //bidids[auction.length -1]
    
    notimes++;
    document.getElementById("bididval").innerHTML = bidids.length ;
     
        if (lastpushbidid <  bidids[auction.length - 1] ) 
        {
            flag = 1;
         }
        else 
        {
            flag = 0;
        }
        
        if ( flag == 1 ) 
        {
              push();
              document.getElementById("msgzone").innerHTML = "calling if cond";
        }
        else
        {
            setTimeout("getXML()", 5000);
            document.getElementById("msgzone").innerHTML = "calling else cond";
        }
          
    }
    
    function push(bidid, itemname, itemvalue, uname, bidvalue, biddate) {
             if (play == 0) {
                    setTimeout("push()", 1000);
                    return;
            }
    
            var cell;
            var cellnext;
            var text;
            var style = "";
            var bidid = bidids.pop();
            var uname = unames.pop();
            var itemname = itemnames.pop();
            var itemvalue = itemvalues.pop();
            var bidvalue = bidvalues.pop();
            var biddate = biddates.pop();
    document.getElementById("bididval").innerHTML = bidids.length ;
            
            lastpushbidid = bidid;                
    document.getElementById("notimes").innerHTML = "Refresh time: " + notimes + " last push id is " + lastpushbidid +" and no of auctions this times are not here"  
            
            text = "<table width=\"100%\">"
            text += "<tr valign=\"top\">";
            text += "<td width=\"185\">" + bidid + "</td>";
            text += "<td width=\"185\">" + itemname + "</td>";
            text += "<td width=\"185\">" + itemvalue + "</td>";
            text += "<td width=\"185\">" + uname + "</td>";                        
            text += "<td width=\"130\">" + bidvalue + "</td>";
            text += "<td width=\"85\">" + biddate + "</td>";
            text += "</tr>";
            text += "</table>";
    //alert(text);
    //
    
            Element.setOpacity('comment-1', 0.0);
    
            for (i = (auctionmax - 1); i >= 1; i--) {
                    cell = document.getElementById("comment-" + i);
                    cellnext = document.getElementById("comment-" + (i + 1));
                    if (cell.innerHTML != "") {
                            cellnext.innerHTML = cell.innerHTML;
                    }
            }
    //
            document.getElementById("comment-1").innerHTML = text;
    
            Effect.Appear('comment-1', { duration: 1.5 });
    
            if (bidids.length > 0) { 
                    setTimeout("push()", 2000);
            }
            else {
                    setTimeout("getXML()", 5000);
            }
    }
    Code (markup):
    Especially the problem in below code.
    :confused:
        
    if (lastpushbidid <  bidids[auction.length - 1] ) 
        {
            flag = 1;
         }
        else 
        {
            flag = 0;
        }
        
        if ( flag == 1 ) 
        {
              push();
              document.getElementById("msgzone").innerHTML = "calling if cond";
        }
        else
        {
            setTimeout("getXML()", 5000);
            document.getElementById("msgzone").innerHTML = "calling else cond";
        }
          
    }
    Code (markup):
    If any new record inserted in table,it should call if (lastpushbidid < bidids[auction.length - 1] ) but why its calling else condition i cant understand so please guide me in this problem.I m try so much to solve this problem in last two days.....:confused:
     
    pushkar, Dec 17, 2006 IP