使用JSON或基于AJAX的定期服务器上直播重定向呼叫 [英] Live redirect based on periodic server calls with JSON or AJAX

查看:198
本文介绍了使用JSON或基于AJAX的定期服务器上直播重定向呼叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的老师要创建自己的对象,一些虚拟的教训,他创造了老师一个版本,为学生和一名。

My teacher want to create some virtual lessons for his object and he created a version for the student and one for the teacher.

他现在问我怎么使用重定向老师控制面板中的学生,从课程到另一个的一部分。

He now asked me how to redirect students using the teacher control panel, from one part of the lesson to another.

我可以做PHP的一部分老师面板和服务器文件被调用每2-3秒钟,看是否有重定向是强制性的。也许这是一个JSON / AJAX的事?

I can do the PHP part for the teacher panel and the server file to be called every 2-3 seconds to see if a redirect is mandatory. Maybe this is a JSON/AJAX thing?

感谢

推荐答案

您可以用这种方法做的。 (学生)

You can do in this way. (for student)

这是学生小组,进行定期的请求的服务器(在5-10秒间隔)。

from student panel, make a periodic request to server (in interval of 5-10 s).

//data is returned by server as json object
//data.route = true or false as validated from database
//data.location is the location new url

$.post("server.php", { "id": "studentid" },
   function(data){  //data is returned by server as json object
     if(data.route)
     {
        window.location = data.location
     }

   }, 
   "json");

在服务器端,你可以做

if(student is to be routed){ //check from the database
    $data['route'] = true;
    $data['location'] = 'location';
}
else{
    $data['route'] = false;
}
echo json_encode($data);

更新::

把上面的AJAX code insde功能

put the above ajax code insde a function

function fun1()
{
//put your ajax code herer
} 

和有关文件准备funcion

and on document ready funcion

$(function(){ setInterval( 'fun1()', 1000) }); 
//use setInterval function
// to call function periodically

您可能会想看看

这篇关于使用JSON或基于AJAX的定期服务器上直播重定向呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆