0

I would like to get the URL from a jQuery success function, after it retrieves data from the server. I could use this.url but the URL changes (same page, just the URL is different). The URL is not to be found locally in the success function, I think:

success: function(data, statusText, jqhxr)

Can you get the new URL in the success function? If it's not possible, are there any other ways to get the updated URL?

Jomity
  • 56
  • 8
  • Does this answer your question https://stackoverflow.com/questions/18763182/ajax-get-url-on-error-jqxhr ? – Fabian S. Oct 15 '21 at 14:35
  • `this` within the AJAX `success` callback references the handler function, so whatever it initially referenced will not be accessible through that keyword. What exactly are you attempting to do, and why? Given that you're making an AJAX call the URL won't change, and if it does it will be through something you're doing programmatically so you should already know what the URL would be changed to...? – Rory McCrossan Oct 15 '21 at 14:38
  • I'm writing a userscript. I'm trying to get the final location of a url. The URL is changing to something I'm not sure of... for example, I'm given the URL example.com/c0h269 and it becomes example.com/c162h269. I was hoping I could use AJAX to read the new URL. – Jomity Oct 15 '21 at 14:50
  • You know the url when you start to ajax call (otherwise where's the ajax going?) so you keep a copy of it. If you're saying the ajax call changes the url, then it sounds like you're saying it's 301/302/303/307 code giving a new url. – freedomn-m Oct 15 '21 at 15:08
  • freedomn-m, The ajax call doesn't change the URL. Also I ran a test and it's not a redirect either. I'm not sure how the URL is changing. – Jomity Oct 15 '21 at 15:48

0 Answers0