【问题标题】:VM3317:1 Uncaught SyntaxError: Unexpected token z in JSON at position 0VM3317:1 未捕获的 SyntaxError:位置 0 处 JSON 中的意外标记 z
【发布时间】:2021-12-06 05:30:05
【问题描述】:

标题是我得到的错误。 ATM 我正在​​将 api 升级到更高版本。现在我得到了这个错误。我试图修复它,但我没有机会。有人可以帮忙吗?

给出错误的代码是

appendCalls(callList = JSON.parse(xhr.responseText));

整个函数:

function getCallList() {
        var date = formatDate(currentDisplayDate);
        callCounter = 0;
        unansweredCalls = 0;
        
        $('#callCounter').html('');
        $('#spinner').addClass('display');
            
        xhr=new XMLHttpRequest();
        
        xhr.onreadystatechange=function() {
            console.log("sd1"); 
            if (xhr.readyState==4 && xhr.status==200) {
                console.log("sd2"); 
                appendCalls(callList = JSON.parse(xhr.responseText));
                console.log("sd3"); 
            }
        }
    
        xhr.open("GET","/api.php?f=calllist&date="+date,true);
        xhr.send();
        
    }

“appendCalls”是另一个函数。需要的话我可以发。

【问题讨论】:

  • 请在问题中包含您的 API 调用返回的 JSON 代码。
  • 尝试记录 xhr.responseText 的内容并查看实际返回的内容,因为它看起来像响应以“z”开头并且不是有效的 JSON。

标签: javascript json xmlhttprequest


【解决方案1】:

是的,我检查了输出(我知道为什么我没想到这一点),发现我有一个以“z”开头的控制台输出。现在可以了,谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 2018-03-18
    • 1970-01-01
    • 2020-07-02
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多