Welcome Guest, Not a member yet? Register   Sign In
Before filters with main page redirect when I call a controller with ajax
#7

(11-24-2022, 11:37 AM)ozornick Wrote: Do you want an unauthorized user to be redirected to the main page when requesting Ajax?
then you need to determine that the request is from XHR and return some status or link. In JS function check "url = redirect or html = paste on page" condition
https://codeigniter.com/user_guide/general/ajax.html

Let me explain, I'm migrating a big application from CI3 to CI4, I'm practically done, I'm trying to fix some things that can still be improved with the new features of CI4.
One of these are filters and the use of before and after.
I already have the same control managed by javascript, but I wanted to take advantage of the filters also avoiding extra http calls.
The behavior must exist both on "normal" calls, and in ajax calls.
If there's no way to tell php/CI to redirect the entire page and not just the ajax-handled portion, I'll stick with the current pure javascript version.
Passing a parameter would also be feasible, but some calls only return html and it would be problematic to modify the whole structure, thanks anyway for the advice, but at this point I think I'll stay with the javascript version
Reply


Messages In This Thread
RE: Before filters with main page redirect when I call a controller with ajax - by serialkiller - 11-25-2022, 01:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB