JavaScript functions ...

Discussion in 'JavaScript' started by redhits, Jun 16, 2008.

  1. #1
    I have this javascript code, the problem is that i can only call it once, after that it won't work again ...

    If I copy and paste the function it will still not work , until i will change variable Ajax into something else like Ajax2...
    but this involve some copy&paste work , and i want to have it for unlimited hits..


    Declaring Ajax on the top won't work , doing Ajax an vector as Ajax[x] won't work

    
    <script type="text/javascript">
    
      
    
    function trimite(url, parametri, divname){
    
    
          if (window.XMLHttpRequest) { Ajax = new XMLHttpRequest();  }
    else if (window.ActiveXObject) {  if(!Ajax){Ajax = new ActiveXObject("Msxml2.XMLHTTP");}
                                      if(!Ajax){Ajax = new ActiveXObject("Microsoft.XMLHTTP");}
                                                   }
    
    function schimbari(){
    if(Ajax.readyState == 4){document.getElementById(divname).innerHTML=Ajax.responseText;}
    
    
    }  
    
    
    Ajax.overrideMimeType('text/html');
    Ajax.open('POST',url,true);
    Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
    Ajax.setRequestHeader("Content-length", parametri);
    Ajax.setRequestHeader("Connection", "close");
    Ajax.send(parametri);
    Ajax.onreadystatechange = schimbari;
    
    
    
    
    
    
    
        
    
    }  
    
            
    
    
    </script>
    HTML:
     
    redhits, Jun 16, 2008 IP
  2. huoyangao

    huoyangao Guest

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How do you use the function? do you call trimite once and schimbari more than once? That could be the problem.
    Your Ajax may be used only once.
     
    huoyangao, Jun 17, 2008 IP