52
var Box = function(){
    this.parm = {name:"rajakvk",year:2010};
    Box.prototype.jspCall = function() {
        $.ajax({
            type: "post",
            url: "some url",
            success: this.exeSuccess,
            error: this.exeError,
            complete: this.exeComplete
        });
    }
    this.exeSuccess = function(){
        alert(this.parm.name);
    }
}

I'm not getting Box object inside exeSuccess method. How to pass Box object inside exeSuccess method?

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
rajakvk
  • 9,775
  • 17
  • 46
  • 49

1 Answers1

81

Use the context option, like this:

    $.ajax({
        context: this,
        type: "post",
        url: "some url",
        success: this.exeSuccess,
        error: this.exeError,
        complete: this.exeComplete
    });

The context option determines what context the callback is called with...so it determines what this refers to inside that function.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • 3
    Extremely sorry. Over sighted jQuery documentation. It is clearly mentioned here http://api.jquery.com/jQuery.ajax/ – rajakvk Oct 05 '10 at 12:23
  • 5
    Maybe clearly mentioned, but not so clear as to how to use it. Nick's example is very helpful. This post goes into even more detail: http://stackoverflow.com/questions/5097191/ajax-context-option – Software Prophets Jul 18 '14 at 14:33