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

}

1
  • 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: stackoverflow.com/questions/11440918/… Commented Oct 7, 2022 at 16:27

1 Answer 1

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.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.