I would like to load the main part of my page with Jquery (using the ‘load’ method):
Example:
$(“#pageContent”).load(“pagex.php”);
But, once I go this file (pagex.php), I would like to make some validations first in it (For instance: check if the user is still logged into site. If it is not logged anymore, redirect it to an external page).
The problem of doing this is that when I redirect it to an external page, this page will be loaded inside ‘my site’.
How could I solve this situation?
I am trying to keep the code ‘well organized’, that’s why I’m loading the subcontents of the page with Jquery’s ‘load’ (to do not need to load all the page layout again), but I’m having no success, because of this ‘validation/redirect stuff’).
Any solution?
Thanks!
You can use redirect from client side, i.e.
In your
pagex.phpyou can check whether the user is logged in or not. If user is logged in then simplyechothe content and if the user is not logged in then you can justechoascriptlikeFrom jQuery .load documentation
Script Execution
When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed.