简体   繁体   English

从其他页面上的链接加载AJAX内容

[英]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. 当您单击该链接时,它将加载“时间表”页面,并且“ ajaxoutput” div会预先填充“ view_games_monday.php”,如下面的函数所示。

Currently, the link pertaining to the function below is on the page "Schedule" which is the SAME page that has the "ajaxoutput" div. 当前,与以下功能有关的链接位于页面“ Schedule”上,该页面是具有“ ajaxoutput” div的SAME页面。

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? 那么,如何设置“星期一的时间表”链接,以在“时间表”页面加载“ ajaxoutput” div中预先填充的“ view_games_monday.php”? 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: 我已经尝试了以下方法,可以加载“计划”页面,但是没有正确的ajax输出:

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 . 您只需要一个页面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. 然后,在导航菜单中,只需使用: index.php?day=tuesday等。

When the php file detects the day, it will print the corresponding information. 当php文件检测到日期时,它将打印相应的信息。 No javascript even needed. 甚至不需要javascript。

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. 您可以像我之前提到的那样将其设置得更奇特,然后将所有时间表打印到页面上,并使用javascript仅显示一天,但是我想这个例子就是您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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