Javascript requires making a copy of this?
In order to pass a 开发者_如何学运维value out of the ajax() success callback, I had to do this:
var a = this;
And then in success()
:
a.myresult = result;
Why is it necessary to make a copy of this? When I tried this.myresult, it did not work.
Inside the context of your ajax callback, the this keyword has changed context.
Outside your method, it referred to some object. Inside the callback, it refers to the jQuery object (since the method is invoked in the context of a jQuery object).
Need to see your code, but my guess is you're using "this" in the context of an anonymous function, so "this" refers to the function.
this
is only meaningful within context. That context within the object's code.
精彩评论