$.ajax context option
All the context
does is it sets the value of this
in the callbacks.
So if you're in an event handler, and you want this
in the callbacks to be the element that received the event, you'd do:
context:this,
success:function() {
// "this" is whatever the value was where this ajax call was made
}
If you wanted it to be some other type, just set that, and this
will refer to that:
context:{some:'value'},
success:function() {
// "this" the object you passed
alert( this.some ); // "value"
}
In the code you added to the question, you could use StateID
, but you wouldn't really need to since you already have access to that variable.
var StateID = $(this).parents('tr').attr('id');
$.ajax({
url: 'Remote/State.cfc'
,data: {
method:'Delete'
,'StateID':StateID
}
,context: StateID
,success: function(result){
alert(this); // the value of StateID
alert(StateID); // same as above
if (result.MSG == '') {
$('#' + result.STATEID).remove();
} else {
$('#msg').text(result.MSG).addClass('err');;
};
}
});
If you set the context option, then this
in success will be whatever you set as the value for context
. So if you pass an object literal containing your input parameter names and values as the context, then in success you could use this.param1
to get the value of your first input parameter.
See the .ajax() docs for more.