XMLHTTPRequest and document.write blanking page error

Discussion in 'Javascript' started by Adam, May 25, 2005.

  1. Adam

    Adam Guest

    This is frustrating me. Opening IE displays the following code fine.
    When I open a new window the code no longer works. All the HTML is
    overwritten with the first document.write statement. Tried with window
    tried without Please help.

    This code pulls XML from a web site then parses it into a dynamically
    created table built with javascript. The write table is not working
    correctly, other methods work fine. This code also locks up Fire Fox to
    where it doesn't stop loading the page.


    var req;
    var textColor;
    var linkColor;
    var columns;
    var tWidth;
    var bgcolor;


    function init () {
    if (window.XMLHttpRequest)
    req = new XMLHttpRequest();

    else if (window.ActiveXObject)
    req = new ActiveXObject("Microsoft.XMLHTTP");

    // req.open("GET", "http://127.0.0.1/patches/AJAX.xml", true);
    req.open("GET",
    "http://127.0.0.1/patches/affiliate_AJAX.cfm?Affiliate=1&Campaign=10",
    true);
    //req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    req.onreadystatechange = callback;

    req.send(null);
    }

    function callback() {
    if (req.readyState == 4) {
    if (req.status == 200) {
    // update the HTML DOM based on whether or not message is valid
    // alert('valid request' + req.status + req.readyState);
    parseMessage();

    // writeTable();
    writeTable();
    return true;

    }
    }

    }

    function parseMessage() {
    var message = req.responseXML.getElementsByTagName("fontcolor")[0];
    textColor = message.childNodes[0].nodeValue;

    message = req.responseXML.getElementsByTagName("linkcolor")[0];
    linkColor = message.childNodes[0].nodeValue;

    message = req.responseXML.getElementsByTagName("tablecols")[0];
    columns = message.childNodes[0].nodeValue;

    message = req.responseXML.getElementsByTagName("tablewidth")[0];
    tWidth = message.childNodes[0].nodeValue;

    message = req.responseXML.getElementsByTagName("bgcolor")[0];
    bgcolor = message.childNodes[0].nodeValue;

    }

    function writeTable() {

    window.document.writeln('<table border="0" cellspacing="10" width="' +
    tWidth + '" bgcolor="#' + bgcolor + '">');

    for (i=0; i<columns; i++) {

    if ((i % columns) == 0)
    window.document.writeln('<tr>');
    //body of each slot
    window.document.writeln('<td>');
    window.document.writeln('test');
    window.document.writeln('</td>');

    if ((i % columns) == (columns - 1))
    window.document.writeln('</tr>'); //end row if column limit is up

    }

    window.document.writeln('</table>');
    }
    GryphonsClaw is online now Edit/Delete Message
    Adam, May 25, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VG9iZQ==?=

    Blanking on Redirect

    =?Utf-8?B?VG9iZQ==?=, Feb 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    318
    Brian K. Williams
    Feb 20, 2004
  2. TylerB
    Replies:
    3
    Views:
    1,555
    TylerB
    Aug 26, 2004
  3. Chris Murphy

    blanking a java.util.Date in 1.5

    Chris Murphy, Sep 18, 2004, in forum: Java
    Replies:
    10
    Views:
    798
    Chris Murphy
    Oct 18, 2004
  4. johnny
    Replies:
    3
    Views:
    2,964
    Tomás Ó hÉilidhe
    Jan 9, 2009
  5. UpRider

    blanking a listbox

    UpRider, Oct 30, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    263
    Alexey Smirnov
    Nov 1, 2009
Loading...

Share This Page