Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Ajax Javascript Onload

  • 06-12-2007 11:21am
    #1
    Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭


    Trying to run two ajax scripts at onload to populate two divs!

    when i run them in the following order:

    showPubList(0,0);
    showCalendar(0,0);

    the calendar div is popluated correctly and not the pub div


    when i run them in the following order:

    showCalendar(0,0);
    showPubList(0,0);

    the pub div is popluated correctly and the calendar div is populated with the pub div

    Doing my head in!
    <script type="text/javascript">
    
    var xmlHttp;
    
    function showCalendar(countyid,month)
    { 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="ajax.php?calendar=1"
    url=url+"&countyid="+countyid
    url=url+"&month="+month
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangedCalendar
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    
    
    
    function showPubList(countyid,letter)
    { 
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
     {
     alert ("Browser does not support HTTP Request")
     return
     }
    var url="ajax.php?publist=1"
    url=url+"&countyid="+countyid
    url=url+"&letter="+letter
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChangedPubList
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    
    
    function stateChangedPubList() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
     document.getElementById("txtPubList").innerHTML=xmlHttp.responseText;
     } 
    }
    
    function stateChangedCalendar() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
     { 
     document.getElementById("txtCalendar").innerHTML=xmlHttp.responseText;
     } 
    }
    
    
    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
     {
     // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     //Internet Explorer
     try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
     }
    return xmlHttp;
    }
    </script>
    


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    Its because "xmlHttp.responseText" is not get unique values - its always going to contain the value of whatever function is being run last

    for example, running it this way

    showCalendar(0,0);
    showPubList(0,0);

    xmlHttp.responseText - will always have the values from showPubList(0,0)

    likewise if you run it the other way

    showPubList(0,0);
    showCalendar(0,0);

    xmlHttp.responseText - will always have the values from showCalendar(0,0);


  • Registered Users, Registered Users 2 Posts: 3,428 ✭✭✭randombar


    Legend!


Advertisement