0

Ok, I'm really at a loss here, and totally can't figure it out.

I have an object literal

say:..

In my object literal,

I call the function, get comments, a property of the object. it turns an AJAX call on and in the AJAX success method, I save the data , to self.commentsData

I have used

var self = this;

before the AJAX and therefore SELF refers to the object and not the AJAX.

But I cannot access this property from anywhere else.

I logged self to console, both from inside the AJAX and outside the AJAX and from another function in the object literal (the AJAX is also part of a function in the object literal) and the weirdest thing shows: inside the AJAX I see my object Class { with all the properties } Outside the AJAX I see the object without the commentsData property, However, if I click on it, the commentsData property does show in the drop down menu, just like it does in the other self log. Using self.commentsData however doesn't seem to work from anywhere in the object except for inside the ajax success method.

I'm really not sure what I'm doing wrong. This almost looks like a bug in javascript, or the chrome console. Has anyone ever seen this before ?

I would post my code but it's fairly long and contains many other functions and would be a tad tedious to look through.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Your ajax call is **asynchronous**. The "inside" part you talk about is the code that the browser calls when the operation is complete. The overall ajax call however returns immediately. – Pointy May 23 '14 at 18:48
  • 1
    Post the full code, that way you won't have to write so much to explain what it does :) – laurent May 23 '14 at 18:49
  • Voting to close, as no code is available. – Antti Haapala -- Слава Україні May 23 '14 at 18:54
  • looks like a duplicate of [How to return the response from an asynchronous call?](http://stackoverflow.com/q/14220321/1048572) and [console.log() async or sync?](http://stackoverflow.com/q/23392111/1048572) – Bergi Jun 07 '15 at 11:07

0 Answers0