yuriy636 yuriy636 - 7 months ago 39
jQuery Question

Access "data" object in AJAX request inside success function

How can I access the

object used in a

url: "post.php",
el1: $('#el1').val(),
el72: $('#el72').val()
success: function(res,status){


You can access the processed options that you passed into $.ajax from within the success callback using this, as long as you didn't bind the function, use an arrow function, or use the context option.

console.log(this.data); // for POST
console.log(this.url); // for GET, but you'll have to parse out the url portion

You'll notice though that it's in a parameterized string rather than an object now because that's how it is sent to the server. See here for ways to convert it back to an object: Convert URL parameters to a JavaScript object

I would just use a variable.