그래서 어떤 스트림이 온라인 또는 오프라인인지 알려주는 배열을 자바 스크립트로 출력하려고합니다. 출력을 알리려고 할 때마다 내 문서의 줄 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>
자바 스크립트
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);
}
?>
My Iframe HTML 파일에 플래시 삽입 객체가 포함되어 있습니다. 무슨 일이 벌어지고 있는지 전혀 모르겠다. 나는 $streams
이 확실히 배열을 반환하므로 무엇을해야할지 모른다. 내 자바 스크립트 디버거에서 오류가 나타납니다. 이에 매개 변수를 추가
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
console.log(xmlhttp.responseText);
var test = JSON.parse(xmlhttp.responseText);
시도를 구문 분석 할 수없는 이유는 볼 대신 응답 텍스트의 값을보고의 를 반환 된 JSON (xmlhttp.responseText를) 구문 분석하는 데 실패처럼
요청에 대한 응답은 무엇입니까? 네트워크 패널 (예 : 자주 이용하는 개발자 도구 패널 참조). 문제를 일으키는 경고가 표시 될 수 있습니다. – Ryan
정확하게 "예기치 않은 토큰"오류 메시지를주는 것은 무엇입니까? 브라우저? 자바 스크립트? PHP? – deceze
자바 스크립트에서 내 오류가 발생했습니다. 내 질문을 업데이트했습니다. 죄송합니다. –