Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Ajax news bar problem

    Hello,
    I have this script;

    Code:
    <html>
    <head>
    <script type="text/JavaScript" language="JavaScript">
    var xmlHttp=false;
    try {
    xmlHttp = new ActiveXObject("Msxml2.xmlHttp");
    } catch (e) {
    try {
    xmlHttp = new ActiveXObject("Microsoft.xmlHttp");
    }
    catch (E) {
    xmlHttp = false;
    }
    }
    if (!xmlHttp && typeof XMLHttpRequest!='undefined') {
    try {
    xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
    xmlHttp=false;
    }
    }
    if (!xmlHttp && window.createRequest) {
    try {
    xmlHttp = window.createRequest();
    }
    catch (e) {
    xmlHttp=false;
    }
    }
    function callServer(){
    //burada šağiracağin sayfayı yazarsın
    var url = "xml.php";
     
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = updatePage;{
    if (xmlHttp.readyState==4) {
    alert(xmlHttp.responseText)
    }
    }
    xmlHttp.send(null)
    }
    function updatePage(){
    //4 sorun yoksa demek
    if(xmlHttp.readyState == 4){
    //gelen cevap
    var response = xmlHttp.responseText;
    //hangi div gelcekse buraya yazılcak
    TICKER.innerHTML = response;
    //500 milisaniyede bir fonksiyonu cağirir
    setTimeout('callServer()',5000);
    }
    }
    callServer('url');
    </script>
    </head>
    <div STYLE="display:none; border-top:1px solid #CCCCCC; border-bottom:1px solid #CCCCCC; overflow:hidden; background-color:#FFFFFF; width:620px" onmouseover="TICKER_PAUSED=true" onmouseout="TICKER_PAUSED=false" id="TICKER">DSADADA</div>
    
    <script type="text/javascript" src="webticker_lib.js" language="javascript"></script>
    
    </html>
    When TICKER DIV is updated, the news bar starts not ticking in Firefox. In Internet Explorer, TICKER DIV is sometimes updating, sometimes not. How can we fix this problem? Thank you,

  • #2
    New Coder
    Join Date
    Mar 2008
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Also, this is the content of webticker_lib.js;

    Code:
    TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
     
    TICKER_RIGHTTOLEFT = false;
    TICKER_SPEED = 2;
    TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
    TICKER_PAUSED = false;
    
    ticker_start();
    
    function ticker_start() {
        var tickerSupported = false;
        TICKER_WIDTH = document.getElementById("TICKER").style.width;
        var img = "<img src=ticker_space.gif width="+TICKER_WIDTH+" height=0>";
    
        // Firefox
        if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {
            document.getElementById("TICKER").innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
            tickerSupported = true;
        }
        // IE
        if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) {
            document.getElementById("TICKER").innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER_STYLE+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>";
            tickerSupported = true;
        }
        if(!tickerSupported) document.getElementById("TICKER").outerHTML = ""; else {
            document.getElementById("TICKER").scrollLeft = TICKER_RIGHTTOLEFT ? document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth : 0;
            document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
            document.getElementById("TICKER").style.display="block";
            TICKER_tick();
        }
    }
    
    function TICKER_tick() {
        if(!TICKER_PAUSED) document.getElementById("TICKER").scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
        if(TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft <= 0) document.getElementById("TICKER").scrollLeft = document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth;
        if(!TICKER_RIGHTTOLEFT && document.getElementById("TICKER").scrollLeft >= document.getElementById("TICKER").scrollWidth - document.getElementById("TICKER").offsetWidth) document.getElementById("TICKER").scrollLeft = 0;
        window.setTimeout("TICKER_tick()", 30);
    }

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi,
    I changed the code as;

    Code:
    if(xmlHttp.readyState == 4){
    var response = xmlHttp.responseText;
    TICKER.innerHTML = response;
    setTimeout('callServer()',5000);
    TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
    TICKER_RIGHTTOLEFT = false;
    TICKER_SPEED = 2;
    TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
    TICKER_PAUSED = false;
    ticker_start(); 
    }
    Now, the content is ticking in Firefox. However, now the text accelerates continuously . What's the crazy problem?

  • #4
    New Coder
    Join Date
    Mar 2008
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Any idea ?

  • #5
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    store your timeout into a variable
    Code:
    ticktock = window.setTimeout("TICKER_tick()", 30);
    and you need to cancel it when you get the Ajax call back
    Code:
    if(xmlHttp.readyState == 4){
      var response = xmlHttp.responseText;
      TICKER.innerHTML = response;
      setTimeout('callServer()',5000);
      TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
      TICKER_RIGHTTOLEFT = false;
      TICKER_SPEED = 2;
      TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
      TICKER_PAUSED = false;
      window.clearTimeout(ticktock);
      ticker_start(); 
    }
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #6
    New Coder
    Join Date
    Mar 2008
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by A1ien51 View Post
    store your timeout into a variable
    Code:
    ticktock = window.setTimeout("TICKER_tick()", 30);
    and you need to cancel it when you get the Ajax call back
    Code:
    if(xmlHttp.readyState == 4){
      var response = xmlHttp.responseText;
      TICKER.innerHTML = response;
      setTimeout('callServer()',5000);
      TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
      TICKER_RIGHTTOLEFT = false;
      TICKER_SPEED = 2;
      TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
      TICKER_PAUSED = false;
      window.clearTimeout(ticktock);
      ticker_start(); 
    }
    Eric
    Hi,
    Where can I store the variable in these codes?

  • #7
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    ticktock is the variable I was talking about.
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #8
    New Coder
    Join Date
    Mar 2008
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by A1ien51 View Post
    ticktock is the variable I was talking about.
    I can't understand anything about Javascript. I tried to change;

    Code:
    if(xmlHttp.readyState == 4){
      var response = xmlHttp.responseText;
      TICKER.innerHTML = response;
      setTimeout('callServer()',5000);
      TICKER_CONTENT = document.getElementById("TICKER").innerHTML;
      TICKER_RIGHTTOLEFT = false;
      TICKER_SPEED = 2;
      TICKER_STYLE = "font-family:Arial; font-size:12px; color:#444444";
      TICKER_PAUSED = false;
      window.clearTimeout(ticktock);
      ticker_start(); 
    }
    And I added

    Code:
    ticktock = window.setTimeout("TICKER_tick()", 30);
    in begining of the codes. Nothing changed :S..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •