Web Analytics Made Easy -
StatCounter Ajax script problem - CodingForum

Announcement

Collapse
No announcement yet.

Ajax script problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ajax script problem

    Hi everyone,The problem is i can't get it to work.It doesn't get the data from the textfile "file.txt" and it says in IE that there is an error on the line where i put <--error on this part-->.Can you tell me what is the problem?Thanks.

    Code:
    <html>
    <head>
    
    <script language="javascript">
    
    var request = false;
    
    if (window.XMLHttpRequest)
    {
    request = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
    request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    
    function getData(datasource,divID)
    {
    if (request)
    {
    request.open("GET", dataSource);
    
    
    request.onreadystatechange = function()
    {
    
    if (XMLHttpRequest.readystate == 4 && request.status == 200)
    {
    
    document.getElementbyId(divID) = request.responseText;
    
    }
    
    }
    
    request.send(null);
    
    </script>
    </head>
    
    <body>
    
    <form>
    <--error on this part-->
    
    <input type = "button" value = "get some data" onclick = "getData('file.txt','targetDiv')">
    
    <--end error-->
    </form>
    
    
    <div id="targetDiv">
    <p> no data retrieved </p>
    </div>
    
    
    
    
    </body>
    
    
    </html>

  • #2
    it looks like you're missing a few }s
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

    Comment


    • #3
      I corrected all the errors that IE have discovered.But it still doesn't get the data.I am using IE.

      Code:
      <html>
      <head>
      
      <script language="javascript">
      
      var request = false;
      
      if (window.XMLHttpRequest)
      {
      request = new XMLHttpRequest();
      }
      else if (window.ActiveXObject)
      {
      request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      
      
      function getData(dataSource,divID)
      {
      if (request)
      {
      request.open("GET", dataSource);
      
      }
      }
      
      
      request.onreadystatechange = function()
      {
      
      if (request.readystate == 4 && request.status == 200)
      {
      
      document.getElementbyId(divID) = request.responseText;
      
      }
      
      
      }
      
      request.send(null);
      
      </script>
      </head>
      
      <body>
      
      <form>
      <input type = "button" value = "get some data" onclick = "getData('file.php','targetDiv')">
      </form>
      
      
      <div id="targetDiv">
      <p> </p>
      
      </div>
      
      
      
      
      </body>
      
      
      </html>

      Comment


      • #4
        did you ever heard for code beautifiers/ formating code. I'm telling you, code like that will hardly anyone look at it.
        Here is sample how it should look like.
        Code:
        request.onreadystatechange = function()
        {
          if ((request.readystate == 4) && (request.status == 200))
          {
            document.getElementbyId(divID) = request.responseText;
          }
        }
        as you see I allso added couple of brackets, that might help too.


        PS

        at least what is missing in problematic line is '/'

        sample:
        <input type="text" name="b" value="b" />
        Last edited by BubikolRamios; Oct 7, 2006, 02:19 PM.
        Found a flower or bug and don't know what it is ?
        agrozoo.net galery
        if you don't spot search button at once, there is search form:
        agrozoo.net galery search

        Comment

        Working...
        X