Итак, я пытаюсь вывести массив в javascript, который скажет мне, если определенные потоки находятся в сети или в автономном режиме. Каждый раз, когда я пытаюсь предупредить выход, он дает мне неожиданный токен «<» в строке 1 моего документа. Это сводит меня с ума. Мой код довольно прямо вперед:Неожиданный токен '<' - AJAX
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Streaming</title>
<style type="text/css">
*{margin:0px;padding:0px;font-family:Arial}
#container{margin:0 auto;width: 1000px}
#player iframe{width:625px;height:510px;}
#player{float:left}
</style>
<script type="text/javascript" src="dynamic.js" ></script>
</head>
<body>
<div id="container">
<div id="player">
<iframe src="streams/tx3fate.html" frameborder="0" scrolling="no"></iframe>
</div>
<iframe frameborder="0" scrolling="no" id="chat_embed" src="http://twitch.tv/chat/embed?channel=day9tv&popout_chat=true" height="500" width="350"></iframe>
</div>
</body>
</html>
Javascript
function getActive() {
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var test = JSON.parse(xmlhttp.responseText);
window.alert(test);
}
}
xmlhttp.open("GET", "streams.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send('check=true');
}
getActive();
PHP
<?php
if($_GET['check'] == true) {
$streams = array(
"mxgdichello" => "offline",
"day9tv" => "offline",
"tx3fate" => "offline",
"wochtulka" => "offline",
"unawaresc2" => "offline",
"xerse" => "offline",
"atree2425" => "offline",
"sc1pio" => "offline",
"lokk_2" => "offline",
"tsremark" => "offline",
"ognastarcraft" => "offline"
);
foreach($streams as $index) {
$json_file = @file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$index}", 0, null, null);
$json_array = json_decode($json_file, true);
if ($json_array[0]['name'] == "live_user_{$index}") {
$index = "online";
} else {
$index = "offline";
}
}
echo json_encode($streams);
}
?>
Мои файлы iframe html содержат только объекты Flash. Я понятия не имею, что происходит - я знаю, что $streams
определенно возвращает массив, поэтому не уверен, что делать. Я получаю сообщение об ошибке в своем отладчике javascript.
Каков ответ на запрос? (См. Панель «Сеть», например, на панели избранных инструментов разработчика.) Может возникнуть предупреждение, вызывающее проблему. – Ryan
Что именно дает вам сообщение об ошибке «неожиданный токен»? Браузер? Javascript? PHP? – deceze
Я получаю свою ошибку в javascript, обновляю свой вопрос, извините. –