473,790 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLHTTPRequest and document.write blanking page error

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.XMLHttp Request)
req = new XMLHttpRequest( );

else if (window.ActiveX Object)
req = new ActiveXObject(" Microsoft.XMLHT TP");

// 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.setRequestH eader('Content-Type','applicat ion/x-www-form-urlencoded');
req.onreadystat echange = 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 .getElementsByT agName("fontcol or")[0];
textColor = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("linkcol or")[0];
linkColor = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("tableco ls")[0];
columns = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("tablewi dth")[0];
tWidth = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("bgcolor ")[0];
bgcolor = message.childNo des[0].nodeValue;

}

function writeTable() {

window.document .writeln('<tabl e 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
Jul 23 '05 #1
2 2715
document.write will not suffice.

there is "state" in a document

that means a "write" is now appended
or destroys a window's canvas?

Look up the write method's other properties

e.g.

open

close

...............

Hope that helps.


"Adam" <ad**@atruerevi ew.com> wrote in message
news:42******** **@alt.athenane ws.com...
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.XMLHttp Request)
req = new XMLHttpRequest( );

else if (window.ActiveX Object)
req = new ActiveXObject(" Microsoft.XMLHT TP");

// 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.setRequestH eader('Content-Type','applicat ion/x-www-form-urlencoded'); req.onreadystat echange = 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 .getElementsByT agName("fontcol or")[0];
textColor = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("linkcol or")[0];
linkColor = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("tableco ls")[0];
columns = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("tablewi dth")[0];
tWidth = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("bgcolor ")[0];
bgcolor = message.childNo des[0].nodeValue;

}

function writeTable() {

window.document .writeln('<tabl e 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


Jul 23 '05 #2
Also a table is not written directly like other tags.

A table has its own little object model going,
since it does obey layout margins.

better clinch it into a seperator first.

e.g.

<div> ........... </div>


"Adam" <ad**@atruerevi ew.com> wrote in message
news:42******** **@alt.athenane ws.com...
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.XMLHttp Request)
req = new XMLHttpRequest( );

else if (window.ActiveX Object)
req = new ActiveXObject(" Microsoft.XMLHT TP");

// 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.setRequestH eader('Content-Type','applicat ion/x-www-form-urlencoded'); req.onreadystat echange = 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 .getElementsByT agName("fontcol or")[0];
textColor = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("linkcol or")[0];
linkColor = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("tableco ls")[0];
columns = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("tablewi dth")[0];
tWidth = message.childNo des[0].nodeValue;

message = req.responseXML .getElementsByT agName("bgcolor ")[0];
bgcolor = message.childNo des[0].nodeValue;

}

function writeTable() {

window.document .writeln('<tabl e 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


Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1892
by: SE | last post by:
Hi all, Apologies if this has been done before. I am trying to do some stuff with XMLHttpRequest in mozilla but no dice. I have finally pared everything down to the minimum to see what is happening with this script ----------------------------------------------------- xmlhttp = new XMLHttpRequest();
42
34247
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox 1.07/Linux, Firefox 1.5/Linux, Firefox 1.5/Windows and Firefox 1.5/Mac, Safari/Mac. It works perfectly on a lot of configurations but, on some PC with Firefox 1.5/Windows (not all), the Javascript code with XmlHttpRequest
1
4183
by: mathewda | last post by:
Hey, I'm having a problem that I consider kinda weird that is alluding me at the moment. I've wrote some code that will set up an XMLHttpRequest, it then makes a call to open and send and sets the onreadystatechange to another function of mine. onreadystatechange checks the ready state and if the ready state is 4 and the status is 200 it assigns to the innerHTML of a div. I also have some code that uses the attachEvent method so that all...
5
2357
by: libsfan01 | last post by:
Hi all Im trying to write a script that pulls data from another page (which is getting data from a db). The contents displayed on the db handling page (display.php) gets transferred through XMLHttpRequest continuously, however when setting the value using getElementById the value of the element is not being replaced, it is being appended each time. Here is my code, how can i modify the code to replace the contents of the element...
5
2408
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML HTTP Request object." In my haze of testing yesterday it seems that NN6.1 provides an non-functional XMLHttpRequest object and NN6.2 XMLHttpRequest object
17
3551
by: broughcut | last post by:
Is it possible to fetch a specific div from a source html document using XMLHttpRequest, rather than fetching the entire file? I was going to use Ajax on mouseover but keep the normal link intact, so that if the user does not have javascript they can click the link as normal and this would take them to the new page, but if they have javascript (and ActiveX enabled I guess, in the case of IE) it would just fetch the appropriate div into...
1
4033
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
1
5305
by: Tarik Monem | last post by:
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest. Can I use PHP do what I'm trying to do? Here's my code: The function mySaveFunction() is called by clicking the "Update" button, after the user changes the data which is populated in the form fields, which was retrieved via XMLHttpRequest from an XML external file. I know that...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.