0

when sending a jquery request and recieving response how to know the url of the request from the response ?

may be like this

function onResoponse(response,url){

requestUrl=url

}

mnwer
  • 23
  • 5
  • Welcome to Stack Overflow. As it is, this is something of a strange question as when you make the AJAX call, you have to define the URL that you are submitting the request to, so it should already be known. What you are looking for is the Response Header. This may help: https://stackoverflow.com/questions/11440918/jquery-get-ajax-response-headers – Twisty Oct 07 '22 at 16:27

1 Answers1

0

Consider the following example.

https://jsfiddle.net/Twisty/kcbp57z4/

JavaScript

$.ajax({
  url: u,
  method: "POST",
  data: d[i],
  success: function(resp, stat, xhr) {
    console.log(stat, this.url);
  },
  error: function(xhr, stat, err) {
    console.log(stat, err, this.url);
  }
});

You can use this to refer to the AJAX object itself. From here you can reference the url properly of the AJAX Object. So if you have multiple AJAX Calls, you can see what URL was used using this.url within the Success callback.

Twisty
  • 30,304
  • 2
  • 26
  • 45