如何通过$ _GET将一个或多个类型数组的变量传递给另一个页面?
我总是在表单中传递变量值 ?a=1&b=2&c=3
传球a=[1,2,3]怎么样?
我是否需要编写for循环并附加所有值?
谢谢
我想它们符合我的要求完美,看起来他们应该是简单的实现获得与服务器端事件交手,但我不能让过去一个模糊的错误,什么样子反复被关闭了连接并重新-opened.我尝试的一切都基于这个和其他教程.
PHP是一个单独的脚本:
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
function sendMsg($id, $msg) {
echo "id: $id" . PHP_EOL;
echo "data: $msg" . PHP_EOL;
echo PHP_EOL;
ob_flush();
flush();
}
$serverTime = time();
sendMsg($serverTime, 'server time: ' . date("h:i:s", time()));
?>
Run Code Online (Sandbox Code Playgroud)
并且JavaScript看起来像这样(在身体负载上运行):
function init() {
var source;
if (!!window.EventSource) {
source = new EventSource('events.php');
source.addEventListener('message', function(e) {
document.getElementById('output').innerHTML += e.data + '<br />';
}, false);
source.addEventListener('open', function(e) {
document.getElementById('output').innerHTML += 'connection opened<br />';
}, false);
source.addEventListener('error', function(e) {
document.getElementById('output').innerHTML += 'error<br />'; …Run Code Online (Sandbox Code Playgroud)