Trying to update Child window with AjaX

M

Mike

Hello,
I am trying to update a child window jpg with JavaScript I seam to get
my error in the Ajax.
Ive used this, and it works, if I want to write to the same window,
but not a new one
Doesnt Work:
newWindow.write(newWindow.getElementById("Graph").src = imageName);
Doesnt Work:
newWindow.getElementById("Graph").src = imageName;

The Entire .js (URL MODIFIED) below. imagename does come back with
exactly what I want.

var xmlHttp;
var newWindow;
function NewGraphWindow(a,b){
if (!newWindow || newWindow.closed) {
newWindow = window.open
("","Graph","status,height=600,width=650");
// delay writing until window exists in IE/Windows
writeToWindow(a,b);
//setTimeout("writeToWindow()", 50);
} else if (newWindow.focus) {
writeToWindow(a,b);
//alert("Window is already opened");
// window is already open and focusable, so bring it to
the front
newWindow.focus();
}


}
function writeToWindow(a,b) {
// assemble content for new window
var newContent = "<html><head><title>Secondary Window</title></
head>";
newContent += "<body>";
newContent += "<img src='petatat.jpg' width='650px'
id='Graph' />";
newContent += "</body></html>";
//process(a,b);
// write HTML to new window document

newWindow.document.write(process(a,b));
newWindow.document.write();
newWindow.document.close(); // close layout stream
// process(a,b);

}
function process(a,b)
{
alert(a);
xmlHttp=GetXmlHttpObject();
//alert(xmlHttp)
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="http://xxxxxxxxxx/GraphDiv.php"

url=url+"?U="+a+"&SType="+b;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
xmlHttp.onreadystatechange=stateChanged
}
function stateChanged()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)

{
// status of 200 indicates the transaction completed successfully
if (xmlHttp.status == 200)
{

// extract the XML retrieved from the server
xmlResponse = xmlHttp.responseXML;
alert(xmlResponse);
// obtain the document element (the root element) of the XML
structure
xmlDocumentElement = xmlResponse.documentElement;
alert(xmlResponse.documentElement);
// get the jpgraph jpg filename, which is in the first child of
// the the document element
imageName = xmlDocumentElement.firstChild.data;
alert(imageName);
// set the src parameter of the image to the retrieved image
name
//document.getElementById("Graph").src = imageName;
newWindow.write(newWindow.getElementById("Graph").src =
imageName); THIS IS WHERE I GET MY ERROR
//newWindow.getElementById("Graph").src = imageName;
alert (newWindow.getElementById("Graph").src);
alert(imageName);
}
// a HTTP status different than 200 signals an error
else
{
setTimeout('stateChanged()', 100);
}


}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
 
T

Thomas 'PointedEars' Lahn

Mike said:
I am trying to update a child window jpg with JavaScript I seam to get
my error in the Ajax.

It sure sea^Heems like so. "Error in the Ajax"? You obviously don't really
know what you are doing.
Ive used this, and it works, if I want to write to the same window,
but not a new one
Doesnt Work:
newWindow.write(newWindow.getElementById("Graph").src = imageName);

(q.e.d.)

Both write() and getElementById() are methods of Document objects, not of
Window objects. Use `newWindow.document.write(...)' and
`newWindows.document.getElementById(...)' instead.

But attempting to write the value of `imageName' (which is the result of the
assignment) will, of course, attempt to write the value of `imageName', and
Doesnt Work:

newWindow.getElementById("Graph").src = imageName;

That looks slightly better (except for newWindow.getElementById(), see
above), but given `imageName' is in fact not the name of the image but the
URI-reference for the image resource,

newWindow.document.images["Graph"].src = imageName;

should suffice already (and is more compatible). And you want to provide
the corresponding `img' element with a `name' attribute instead, it's more
compatible (except in XHTML which you want to avoid).

Given your posting, I strongly suggest you start at least two levels below
what you are trying to do. You can't build a castle on a swamp.
The Entire .js (URL MODIFIED) below. imagename does come back with
exactly what I want.
[snipped 100+ lines of uncommented junk]

No, thanks. And your feature test, if it deserves to be called that, is
misguided; IE 7+ also supports XMLHttpRequest(), but it doesn't work for
local files, in contrast to ActiveXObject(). So you might want to switch
order (and maybe you want to eval() try...catch since it breaks the script
with incompliant script engines.)

<http://jibbering.com/faq/#posting>


PointedEars
 
A

AMP

Mike said:
I am trying to update a child window jpg with JavaScript I seam to get
my error in the Ajax.

It sure sea^Heems like so.  "Error in the Ajax"?  You obviously don'treally
know what you are doing.
Ive used this, and it works, if I want to write to the same window,
but not a new one
Doesnt Work:
 newWindow.write(newWindow.getElementById("Graph").src = imageName);

(q.e.d.)

Both write() and getElementById() are methods of Document objects, not of
Window objects.  Use `newWindow.document.write(...)' and
`newWindows.document.getElementById(...)' instead.

But attempting to write the value of `imageName' (which is the result of the
assignment) will, of course, attempt to write the value of `imageName', and
Doesnt Work:

 newWindow.getElementById("Graph").src = imageName;

That looks slightly better (except for newWindow.getElementById(), see
above), but given `imageName' is in fact not the name of the image but the
URI-reference for the image resource,

  newWindow.document.images["Graph"].src = imageName;

should suffice already (and is more compatible).  And you want to provide
the corresponding `img' element with a `name' attribute instead, it's more
compatible (except in XHTML which you want to avoid).

Given your posting, I strongly suggest you start at least two levels below
what you are trying to do.  You can't build a castle on a swamp.
The Entire .js (URL MODIFIED) below. imagename does come back with
exactly what I want.
[snipped 100+ lines of uncommented junk]

No, thanks.  And your feature test, if it deserves to be called that, is
misguided; IE 7+ also supports XMLHttpRequest(), but it doesn't work for
local files, in contrast to ActiveXObject().  So you might want to switch
order (and maybe you want to eval() try...catch since it breaks the script
with incompliant script engines.)

<http://jibbering.com/faq/#posting>

PointedEars

Thanks for your Comments, but:
It works WITH:
newWindow.document.getElementById("Graph").src = imageName;
AND
I moved process(a,b) to the end of writeWindow......thats all

Thanks
Mike
 
T

Thomas 'PointedEars' Lahn

AMP said:

I wrote that for a reason.

Thanks for your Comments, but:
It works WITH:

Works *where*, *when*?
newWindow.document.getElementById("Graph").src = imageName;

That it works in your browser(s) is no indication that it is good.
Mark my advice.
AND
I moved process(a,b) to the end of writeWindow......thats all

Good luck. You're going to need it.

BTW: Learn to quote. And why are you changing the From anyway?

<http://jibbering.com/faq/#posting> (again)


Score adjusted

PointedEars
 
A

AMP

AMP said:

I wrote that for a reason.
Thanks for your Comments, but:
It works WITH:

Works *where*, *when*?
 newWindow.document.getElementById("Graph").src = imageName;

That it works in your browser(s) is no indication that it is good.
Mark my advice.
AND
I moved process(a,b) to the end of writeWindow......thats all

Good luck.  You're going to need it.

BTW: Learn to quote.  And why are you changing the From anyway?

<http://jibbering.com/faq/#posting> (again)

Score adjusted

PointedEars

I'm not changing the From. its what I log i from, Google, OE.....
"Good Luck Your going to need it"
Whats up with THAT?
 
L

Logos

AMP said:
I'm not changing the From. its what I log i from, Google, OE.....
"Good Luck Your going to need it"
Whats up with THAT?

Don't rush to take offense. While a font of good advice and
javascript (excuse, ECMAscript) arcana, Pointed Ears can be rather
brusque and stuffy sometimes. And all he means is that you need more
experience and learning about javascript as your question shows that
you don't have a good grasp of the fundamentals.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top