Reputation: 1071
I have a page (page.php) whose content is dynamic (let's say there are 3 different contents available). The content which is loaded depends on which link of the menu we have clicked on. My problem is next : I am on this page (page.php) with the contentA loaded. I would like to say :
if (...){
<script>
location.href = "page.php";
$(".content-area").load("content-B.php");
</script>
}
How could I do this ? Thanks !
Upvotes: 2
Views: 607
Reputation: 1338
"location.href" will reload your page, causing the javascript to stop executing from that point forward. If you want to reload the page with page.php for some reason, then you might do something like:
location.href = "page.php?content=b"
And then you can use PHP in page.php to look for a "content" parameter and load the appropriate content using an include, or some other technique. Something like this would go in your page.php:
if(isset($_GET["content"]) && trim($_GET["content"]) == 'a'){
include 'a.php';
} else if(isset($_GET["content"]) && trim($_GET["content"]) == 'b') {
include 'b.php';
} else if(isset($_GET["content"]) && trim($_GET["content"]) == 'c') {
include 'c.php';
} else {
include 'default.php';
}
Upvotes: 0