很抱歉重新发布此问题,但是在搜索了几天互联网并查看了 stackoverflow 和许多其他网站之后,我仍然没有更接近解决这个问题。当谈到 JavaScript 时,我是一个大菜鸟,我似乎一直被困在这上面。
以下代码似乎存在问题。我不断收到错误消息: Uncaught SyntaxError: Unexpected token < xhr.onload
function getFile(fileId){
log('Checking whether to resume upload');
var fileData = localStorage[fileId];
if (fileData){
var fileParts = fileData.split("|");
log ('Resuming upload from package '+(parseInt(fileParts[2])+1));
setDetails({
fileId:fileParts[0],
token:fileParts[1],
currentPackage:fileParts[2]
});
}else{
log ('No upload to resume, informing server to initialize a new upload');
// submit file information to server
var formData = new FormData();
formData.append('totalSize', self.totalSize);
formData.append('type', self.type);
formData.append('fileName', self.fileName);
//error lies from here on
var xhr = new XMLHttpRequest();
xhr.open('POST', self.url, true);
xhr.onload = function(e) {
var response = JSON.parse(xhr.responseText);
if (response.action=="new_upload"){
log ('New upload initialized with ID '+response.fileid+' and token '+response.token);
setDetails(setFile(fileId,response.fileid,response.token));
}
};
我一生都无法弄清楚我哪里出了问题。任何将我指向适当方向的帮助都会很棒。到目前为止,我已经尝试删除所有 < 字符,但仍然没有运气。我什至在 Jsonlint.com 上尝试验证,但仍然没有这样的运气。
//managed to track the error dow to this through JSONlint:
{
responseText="<br><table border='1' c.../div></td></tr></table>",
mozResponseArrayBuffer=ArrayBuffer,
more...
}
//with the error output as:
Parse error on line 1:
{ responseText="<br><t
-----^
Expecting 'STRING', '}'
我在哪里做错了?