简体   繁体   中英

Load AJAX content from a link on a different page

I would like to create a link, let's call it "Monday's Schedule". When you click on that link, it loads the "Schedule" page and the "ajaxoutput" div is pre-populated with "view_games_monday.php" as shown in the function below.

Currently, the link pertaining to the function below is on the page "Schedule" which is the SAME page that has the "ajaxoutput" div.

document.getElementById('games_monday').onclick = function()
{
    callPage('view_games_monday.php',document.getElementById("ajaxoutput"));
}


<a href="#" id="games_monday">monday</a>

<div id="ajaxoutput">
</div>

So how can I setup the "Monday's Schedule" link to load the "Schedule" page with the "view_games_monday.php" pre-populated in the "ajaxoutput" div? My issue is that "Monday's Schedule" link is not on the "Schedule" page.

Sorry for all the quotes just trying to be clear.

Thank you for your help.

I've tried the following and can get the Schedule page to load but not with the correct ajax output:

document.getElementById('schedule_monday').onclick = function()
    {
        location = "http://mydomain.com/schedule";
        this.document.location.href = location;
        window.onload = callPage('http://mydomain.com/view_games_monday.php',document.getElementById("ajaxoutput"));
    }

Based on our comment discussion, here's what I suggest based on my understanding of what you want.

You only need a single page, index.php . This is extremely basic, but conveys the point:

<?php

$scheduleDay = (isset($_GET['day']) ? $_GET['day'] : 'monday');

if( $scheduleDay == "monday" ){
   print 'stuff for monday goes here';
}
else if( $scheduleDay == "tuesday" ){
   print 'stuff for tuesday goes here';
}

Then, in your navigation menu, just use: index.php?day=tuesday , etc.

When the php file detects the day, it will print the corresponding information. No javascript even needed.

You could make it fancier like I had mentioned, and print all of the schedules onto a page and use javascript to display only a single day, but I assume this example is what you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM