2012-11-21 53 views
0

對不起,重新發布這個,但在搜索了幾天的互聯網和翻閱stackoverflow和許多其他網站後,我仍然沒有接近解決這個問題。當談到JavaScript時,我是一個非常棒的noob,而且我似乎一直在堅持這一點。未捕獲的SyntaxError:意外的令牌<jsUpload.js:97 xhr.onload

下面的代碼似乎有問題。我不斷收到錯誤:未捕獲的SyntaxError:意外的標記< 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', '}' 

我在哪裏出錯了?

+0

如果你編輯一箇舊帖子,它將會在最後一次編輯的時候再次進入'有趣'頁面。無需重新發布! – 11684

+1

這只是你的文章中的一個錯字:'JSON.parse('xhr.responseText');'? 'xhr.responseText'應該在這裏沒有引用。 – Teemu

+0

噢,那是我的錯,那是我的一個錯字。 –

回答

0

我修正了它,因爲它試圖解析整個網頁。在使用Mozilla Firebug進一步追蹤我的錯誤後立即修復。

相關問題