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?

1 Answer 1

80

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Extremely sorry. Over sighted jQuery documentation. It is clearly mentioned here api.jquery.com/jQuery.ajax
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: stackoverflow.com/questions/5097191/ajax-context-option

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.