Jakob,

>I've written a javascript class in which there is a function which
>makes a ajax request.
>
>But the callback function of this $.ajax don't know the objects
>variables. Why is that.
>
>It looks something like this:
>
>function FileView(fbId, rootFolder, showFolders, type) {
>
>       this.tmpVar = 'somuch';
>
>       FileView.prototype.choseFolder = function(folderId, type,
>showFolders)
>       {
>               alert(this.tmpVar); // displays somuch
>
>               $.ajax({        type: "POST",
>                       url: "file.php",
>                       data: "actions",
>                       success: function(msg) {
>                               alert(this.tmpVar); // displays undefined
>                       }
>               });
>       }
>}
>
>What am I doing wrong. It could be something with my class - it's the
>first time I'm doing oop in javascript.

The reference to "this" changes when inside the callback. You'll need to
store "this.tmpVar" into a private variable:

this.tmpVar = 'somuch';
var privateTmpVar = this.tmpVar;

Now you should be able alert the variable privateTmpVar in your success
callback.

-Dan

Reply via email to