/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How to pass a function/variable-reference to xmlhttprequest-onload-event?

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(…)” .
Edit: I should add, that this will only running locally on Firefox.

Here is an example-page:

[CODE]<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 + “nn” + 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 + “nn” + 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>
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@dh2006authorJun 06.2007 — GREAT! The solution I got on some other great forum. ?

I post it here too. It's so simple, me nearly came some tears.

Thanks again to Eric.


[CODE]
var req = this;
function onLoad (e) {
req.HTMLofURL = e.target.responseText;

...
}
[/CODE]


Eric
[/QUOTE]
×

Success!

Help @dh2006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...