Hi,
I''ve written a very simple javascript page and found that the object
member variable can''t be accessed inside the Ajax.request. In the
following codes, alert(this.name) doesn''t show anything. Is there
anything wrong with my codes? Is it a bug? My config is scriptaculous-
js-1.7.0, IE6, XP SP2.
Thanks
<html>
<head>
<title>Test Page</title>
<script src="javascripts/prototype.js"
type="text/javascript"></
script>
<script src="javascripts/scriptaculous.js"
type="text/javascript"></
script>
<script type="text/javascript">
function Cache()
{
this.name="Stock Request"
this.replyFailed=function(resp)
{
}
this.replyOK=function(resp)
{
alert(this.name) // nothing is printed here
}
this.request=function()
{
var url="http://www.yahoo.com"
new Ajax.Request(url, {method: "get", onSuccess: this.replyOK,
onFailure: this.replyFailed})
}
}
var cache=new Cache()
cache.request()
</script>
</head>
<body></body>
</html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
this is no bug in prototype rather a problem in your code: you have to
bind the request function to Cache Object for this to work. without
bind the scope for the request function will be the window object.
this.request=function()
{
var url="http://www.yahoo.com"
new Ajax.Request(url, {method: "get", onSuccess: this.replyOK,
onFailure: this.replyFailed})
}.bind(this)
also look at: http://www.prototypejs.org/api/function#method-bind
Maybe you already know this but a different problem with your code is
that an ajax request to yahoo or whatever url different from yours
will fail because of security restrictions...
dasboe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi, I''m a new comer to prototype and didn''t notice this. Thanks for your help. It solves my problem. CM On 5月28日, 下午6時39分, dasboe <bjo...-C/9M+bQ+NTHNxMFbcLXDcQ@public.gmane.orge> wrote:> this is no bug in prototype rather a problem in your code: you have to > bind the request function to Cache Object for this to work. without > bind the scope for the request function will be the window object. > > this.request=function() > { > var url="http://www.yahoo.com" > new Ajax.Request(url, {method: "get", onSuccess: this.replyOK, > onFailure: this.replyFailed}) > }.bind(this) > > also look at:http://www.prototypejs.org/api/function#method-bind > > Maybe you already know this but a different problem with your code is > that an ajax request to yahoo or whatever url different from yours > will fail because of security restrictions... > > dasboe--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thx a lot dasboe to share this info. On May 28, 3:39 pm, dasboe <bjo...-C/9M+bQ+NTFiszJb17IBaA@public.gmane.org> wrote:> this is no bug in prototype rather a problem in your code: you have to > bind the request function to Cache Object for this to work. without > bind the scope for the request function will be the window object. > > this.request=function() > { > var url="http://www.yahoo.com" > new Ajax.Request(url, {method: "get", onSuccess: this.replyOK, > onFailure: this.replyFailed}) > }.bind(this) > > also look at:http://www.prototypejs.org/api/function#method-bind > > Maybe you already know this but a different problem with your code is > that an ajax request to yahoo or whatever url different from yours > will fail because of security restrictions... > > dasboe--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---