![](/img/trans.png)
[英]Uncaught SyntaxError: Unexpected token ( error in Javascript
[英]Error: Uncaught SyntaxError: Unexpected token < javascript
一直在四處尋找意外令牌<的解決方案,但它們都沒有幫助我,或者也許我找不到它。 無論如何,這是我的代碼,希望有人能夠看到我所缺少的內容。 控制台指示錯誤在以下行中:“ var vec = JSON.parse(data);”
謝謝!
(function()
{
var xhr = new XMLHttpRequest();
xhr.open("GET","https://nodejs-c9-nathan14.c9.io",false);
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4 && xhr.status == 200)
{
var list = document.getElementById('list');
var total_tasks = document.getElementById('total_tasks');
var data = xhr.responseText;
var vec = JSON.parse(data);
vec.forEach(
function(ob)
{
var li = document.createElement("li");
var a = document.createElement("a");
var div_head = document.createElement("div");
var div_content = document.createElement("div");
var delete_button = document.createElement("a");
var date_image = document.createElement("img");
div_head.className = "list_head";
div_content.className = "list_content";
// Get and set task name
var task_name = document.createTextNode(ob.task);
a.appendChild(task_name);
a.setAttribute("href","edit.html?" + ob.id);
// Set date image
date_image.setAttribute("src","themes/images/sort_due_date.png");
// Get date and fix to remove time
var temp_task = ob.due_date;
var temp_task_string = temp_task.toString();
var temp_task_string_cut = temp_task_string.slice(0,10);
var task_date = document.createTextNode(temp_task_string_cut);
// Set delete button
delete_button.setAttribute("data-role","button");
delete_button.setAttribute("data-icon","delete");
delete_button.setAttribute("data-iconpos","notext");
delete_button.setAttribute("data-theme","b");
delete_button.setAttribute("href","#delete_dialog?" + ob.id);
delete_button.className = "ui-btn-right";
// Append vars into DOM
div_head.appendChild(a);
div_content.appendChild(date_image);
div_content.appendChild(task_date);
div_content.appendChild(delete_button);
li.appendChild(div_head);
li.appendChild(div_content);
list.appendChild(li);
}
);
$('#list').listview('refresh');
}
}
xhr.send();
})();
根據您提供的內容,我想您會在響應中得到除JSON之外的其他信息(很可能是HTML,給出對<
的引用)。 我建議進行調試,並查看一下data
變量中的內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.