...

View Full Version : SOLVED: How to pass a function/variable-reference to XMLHttprequest-onload-event?



DH2006
06-06-2007, 01:26 PM
Hello!
How to pass a function- or variable-reference to the xmlhttprequest-onload-event? The function and the variable are part of an object genereated with "tempObj = new Seite(...)" .
I should add, that this will only running locally on Firefox.
The error i get in the Javascript-Console is "this.callMeFromOnLoad is not a function"

Here is an example-page:

<html>
<head>
<title>Why are the lines marked by "//<===" not working? How to pass that function call to the function onLoad?</title>
<script language="javascript" type="text/javascript">
Seite = function(fuURL,fuText) {
this.status = 0; this.theURL = fuURL; this.myId = fuText;
this.HTMLofURL = 'placeholder-text';
function callMeFromOnLoad(aURL,aHTMLsource) { alert(this.myId); }
function onLoad (e) {
this.HTMLofURL = e.target.responseText; //<=== "this.HTMLofURL" will actually not be the "this.HTMLofURL" as two lines above, when called from the
// XMLHttoRequest onload-event ):
testAlert(this.theURL + "\n\n" + this.HTMLofURL); // "this.theURL" isn't the same as the "this.theURL" from above
this.callMeFromOnLoad(this.theURL,this.HTMLofURL); //<=== same here
}
this.LoadPage = function() {
try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("Permission UniversalXPConnect denied."); }
var r = new XMLHttpRequest();
r.onload = onLoad;
r.open ("GET", this.theURL, true);
r.send (null);
}
}
function testAlert(fuText) { alert(fuText);}
function testSearch() {
var tempObj;
tempObj = new Seite('http://www.google.com','TestObj1');
tempObj.LoadPage();
}
</script>
</head>
<body onLoad="testSearch();">
Hello
<pre>
How to pass a function- or variable-reference to the xmlhttprequest-onload-event? The function and the variable are part of an object genereated with "tempObj = new Seite(...)" .
Why are the lines marked by "//<===" not working? How to pass that function call to the function onLoad?
this.HTMLofURL = e.target.responseText; //<=== "this.HTMLofURL" will actually not be the "this.HTMLofURL" as two lines above, when called from the
// XMLHttoRequest onload-event ):
testAlert(this.theURL + "\n\n" + this.HTMLofURL); // "this.theURL" isn't the same as the "this.theURL" from above
this.callMeFromOnLoad(this.theURL,this.HTMLofURL); //<=== same here
</pre>
<span id="id:forFastOutput"></span>
</body></html>

A1ien51
06-06-2007, 03:12 PM
var req = this;
function onLoad (e) {
req.HTMLofURL = e.target.responseText;
...
}


Eric

DH2006
06-06-2007, 06:53 PM
Wow! I will test it.
But I will only believe it, after i have tested it. :P




var req = this;
function onLoad (e) {
req.HTMLofURL = e.target.responseText;
...
}


Eric

If this really is a solution, that would be amazing, taking into account that I used up around 1 day and crawled through different javascript-sources and forums - where I only found one thread that might contain a solution, though not directly for what i asked for.

Dieter

DH2006
06-06-2007, 07:09 PM
!!!! TYVM!!!!
Me nearly came some tears.
I'm not gay, but I would kiss you now, if you were in reach. :P





var req = this;
function onLoad (e) {
req.HTMLofURL = e.target.responseText;
...
}


Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum