Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-06-2007, 01:26 PM   PM User | #1
DH2006
New Coder

 
Join Date: May 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
DH2006 is an unknown quantity at this point
SOLVED: 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(...)" .
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:
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 + "\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>
DH2006 is offline   Reply With Quote
Old 06-06-2007, 03:12 PM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
Code:
var req = this;
function onLoad (e)    {
      req.HTMLofURL = e.target.responseText;  
     ...
}
Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 06-06-2007, 06:53 PM   PM User | #3
DH2006
New Coder

 
Join Date: May 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
DH2006 is an unknown quantity at this point
Wow! I will test it.
But I will only believe it, after i have tested it. :P

Quote:
Originally Posted by A1ien51 View Post
Code:
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 is offline   Reply With Quote
Old 06-06-2007, 07:09 PM   PM User | #4
DH2006
New Coder

 
Join Date: May 2006
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
DH2006 is an unknown quantity at this point
!!!! TYVM!!!!
Me nearly came some tears.
I'm not gay, but I would kiss you now, if you were in reach. :P


Quote:
Originally Posted by A1ien51 View Post
Code:
var req = this;
function onLoad (e)    {
      req.HTMLofURL = e.target.responseText;  
     ...
}
Eric
DH2006 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:51 PM.


Advertisement
Log in to turn off these ads.