The key here is the A in Ajax - asynchronous. As Nate illustrates, your
request goes to the server for data but your code continues executing. This
is where callbacks (events) allow you to defer behavior until the request
has completed.
On Thu, Aug 27, 2009 at 4:58 PM, nwhite wrote:
> drew.. you
drew.. your setting this values on an ajax request. but your calling alert
before the ajax call even gets back. This is where you need to use events.
I made changes so the data gets set and shows in the alert when it is
updated.
http://mooshell.net/ezgn6/
On Thu, Aug 27, 2009 at 1:13 PM, drew n
How about this example:
http://mooshell.net/PYMMR/
I just modified your example, but tried setting an instance variable
within the onSuccess function, and then accessing it from within
another function. Still doesn't work.
On Aug 26, 8:39 am, Aaron Newton wrote:
> drew, it's hard for us to te
drew, it's hard for us to tell you what's going wrong with your code without
seeing it all. We can tell you that this stuff does work and it's relatively
straight forward.
here's a working example of request.json:
http://mooshell.net/UDa6m/
On Tue, Aug 25, 2009 at 3:43 PM, drew n wrote:
>
>
If modify the code to the following.
updateDemo: function(id) {
this.id = id;
this.testCall();
},
testCall: function() {
alert(this.id);
}
It still does not return the id. I'm assuming at this point when I
call testCall() that the request has been complet
You are alerting a variable right away, but it is set asynchronously. You
don't set the id till after the request returned, but you tried to alert it
immediately.
On Tue, Aug 25, 2009 at 5:10 PM, drew n wrote:
>
> Still nothing. I've tried to strip out everything from code and break
> it down t
Still nothing. I've tried to strip out everything from code and break
it down to the essentials.
I've upload the code as a gist so it's easier to read, but here's what
I've got.
http://gist.github.com/175070
Now, if i make the following javascript calls
var d = new Demo();
d.save();
aler
Maybe you need to bind the updateDemo function inside onSuccess
from:
onSuccess: function(d) {
this.updateDemo(d.demo.id, d.demo.name);
this.id = d.demo.id;
}.bind(this)
to:
onSuccess: function(d) {
this.updateDemo.bind(th
The binds property still isn't doing the trick for me.
All I'd like to be able to do is run a mootools Request.JSON to the
server and then assign the data returned from the server to an
instance variable in my javascript class. Is there any generalized
example for doing this? I'm pretty sure i'm
You could change it to this:
var Demo = new Class({
Binds: ["updateDemo", "save", "success"],
save: function() {
var req = new Request.JSON({
url: "/demos.json",
method: "post",
data: {"demo[name]":this.name,
"au
var Demo = new Class({
save: function() {
var req = new Request.JSON({
url: "/demos.json",
method: "post",
data: {"demo[name]":this.name,
"authenticity_token":this.auth_token},
onSuccess: function(d) {
I'd log all the variables to make sure you're getting what you think
you are:
onSuccess: function(d) {
console.log(d)
}
On Aug 25, 2009, at 1:24 PM, drew n wrote:
The following code requests information about an object, and then
tries to set a couple class variables based on the data r
12 matches
Mail list logo