If using ajax, you can just pre-build a variable of page (uri) needed. But ajax doesn't always match the current uri as things are happening in the background.
Question about getting the current url of the page the user is on
So in my controller I'd like to get the current page url the user is on.
I use Ajax on the client side, something like this:
$.ajax({
type: 'POST',
url: {{ url('/loadcomments') }},
// etc.
});
When I get the current url in my controller I'll get {{ url('/loadcomments') }} which is not what I want but I noticed if I use:
url()->previous()
This provides the correct URL. Which makes sense since the last url was {{ url('/loadcomments') }}.
My question is, is it ok to do it this way? Or are there edge cases where this would provide unexpected results?
Originally I passed the current URL as data via Ajax but I was trying to make it a bit more elegant. Are there any edge cases I should take in to consideration or is it fine to do it this way?
It seems what I'm looking for is:
Request::server('HTTP_REFERER')
Thank you to everyone that replied.
Please or to participate in this conversation.