Try wrapping the "this" inside parentheses:

$(this).someMethod 

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of CF
Sent: Monday, April 02, 2007 3:48 AM
To: jQuery (English)
Subject: [jQuery] [Newbie] Why this. doesn't work?


Hi,
I have this Javascript in JSON notation and using the jQuery Ajax.

var objectJSON = {
        myvalue: "hello",
        myFunction: function(param) {
                this.myvalue = param;
                $.ajax({
                type: "POST",
                url: '/ajax/address.php',
                data: "param=" + param,
                success: this.pageLoadOk
                });
        },
        pageLoadOk: function(t){
                $('#id-element').html(t);
                alert(this.myvalue);   //*** this.myvalue is not
accesible from here ***//
                alert(objectJSON.myvalue);  //***It works **//

        },
        ............

It seems that from myFunction I can access "this.myvalue" but not in
pageLoadOk which the function It is executed when returning the Ajax
response. I could do alert(objectJSON.myvalue) and it would work but I would
prefer not to use instance names variables.
My knowledge of Javascript is not very good and I am sure I am doing
something wrong....

Thanks for your help
CF


Reply via email to