suppose i have a php database connection file. Consider two cases if there is an connection error :
- If request is a normal request (not ajax) then i would simply echo a message and exit.
- If request is a ajax request then i have to use json encode to send status and msg to client side js.
How can i separate the logic for above code, or how is this normally handled by you guys.
Consider another case : If a login in session is expired :
- If request is a normal request (not ajax) then i would simply use header('location: login.php');
- If request is a ajax request then ? (should i need to send a status code to client side and then use window.location )