dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: AJAX - Unknown Runtime Error

  1. #1
    Join Date
    Jun 2006
    Posts
    1

    AJAX - Unknown Runtime Error

    Code:
    document.write ("<p id=ad"+ADid+">LOADING</p>");
    adGrab(ADtags, ADtitle);
    
    function getHTTPObject(){ if(typeof XMLHttpRequest!='undefined') { return new XMLHttpRequest();} 
    
    try{ return new ActiveXObject("Msxml2.XMLHTTP");} catch (e){try{ return new 
    
    ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}} return false;}
    
    function adGrab(ADtags, ADtitle) {
     myurl = "http://ads.ismywebsite.com/ad.php?title="+ADtitle+"&tags="+ADtags+"&t="+Date.parse(new 
    
    Date());
     http = getHTTPObject();
     alert (1);
     http.open("GET", myurl, true);
     alert (2);
     http.onreadystatechange = adShow;
     alert (3);
     http.send(null);
     alert (4);
    }
    
    function adShow() {
     alert (5);
     if (http.readyState == 4) {
      var text = http.responseText;
      alert (6);
      alert("document.getElementById('ad"+ADid+"').innerHTML = '"+text+"'");
      alert (7);
      var name = 'ad'+ADid;
      alert (name+"-"+text);
      if (document.getElementById) {
       document.getElementById(name).innerHTML = text;
       alert (8);
      }
      else if (document.all) { document.all[name].innerHTML = http.responseText; alert (9);}
      else if (document.layers) { document.layers[name].innerHTML = http.responseText; alert (10);}
     }
     alert (11);
    }
    Line 28, Char 4 apparantly. As you can see by all the alerts, I'm doing a lot of debugging.

    See my code live at http://ads.imywebsite.com/adtest2.php

    I've been messing with this for a couple days already...

  2. #2
    Join Date
    Apr 2007
    Location
    Sunny Adelaide
    Posts
    13
    Hi,

    I suggest you grab Firebug, which is an excellent extension for Firefox that provides step-through JavaScript debugging capabilities. It is a must for any serious development.

    Indent and space your code properly (new line and indent after opening brace, outdent on closing brace) and you will find it easier to manage.

    You shouldn't need to be testing document.all and document.layers like that. That stuff died out in the 90s.

    Finally:- never use document.write(). Instead, look at the DOM for any manipulation of the page.

    Rewrite your code following all of these good practices and I daresay your error will probably go away or at the very least be much easier to hunt down and fix.

    Regards,
    - P
    Brevitywit

Similar Threads

  1. wot is CLR
    By lostguy in forum .NET
    Replies: 8
    Last Post: 04-03-2002, 07:41 PM
  2. Runtime error 6160, data access error.
    By Pat in forum VB Classic
    Replies: 2
    Last Post: 01-29-2002, 04:18 AM
  3. NullPointerException when reading text file
    By Andrew McLellan in forum Java
    Replies: 3
    Last Post: 05-09-2001, 05:34 PM
  4. Runtime error
    By seye in forum VB Classic
    Replies: 1
    Last Post: 03-09-2001, 12:48 PM
  5. Runtime Error
    By Joseph Marcelo in forum VB Classic
    Replies: 8
    Last Post: 07-25-2000, 02:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center