简体   繁体   English

Javascript 错误:SyntaxError: JSON.parse: JSON 数据第 1 行第 1 列的数据意外结束

[英]Javascript error: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

I have a CS:GO betting website and when I try to go to the page to withdraw skins or something like that after I verify that i am not a robot using recaptcha I get this error:我有一个 CS:GO 博彩网站,当我在验证我不是使用 recaptcha 的机器人后尝试转到该页面以提取皮肤或类似内容时,我收到此错误:

Javascript error: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data Javascript 错误:SyntaxError: JSON.parse: JSON 数据第 1 行第 1 列的数据意外结束

Here is the code :这是代码:

function redeem(){
    var code = $("#promocode").val();
    $.ajax({
        url:"/redeem?code="+code,
        success:function(data){     
            try{
                data = JSON.parse(data);
                if(data.success){
                    bootbox.alert("Success! You've received "+data.credits+" credits.");                    
                }else{
                    bootbox.alert(data.error);
                }
            }catch(err){
                bootbox.alert("Javascript error: "+err);
            }
        },
        error:function(err){
            bootbox.alert("AJAX error: "+err);
        }
    });
}

Here is my syntax error:这是我的语法错误:

SyntaxError: Unexpected end of JSON input
at Object.parse (native)
at Object.$.ajax.success (http://www.gamesnodie.com/template/js/offers.js?v=106:249:29)
at j (http://www.gamesnodie.com/template/js/jquery-1.11.1.min.js:1:27244)
at Object.k.fireWith [as resolveWith] (http://www.gamesnodie.com/template/js/jquery-1.11.1.min.js:1:28057)
at x (http://www.gamesnodie.com/template/js/jquery-1.11.1.min.js:1:85993)
at XMLHttpRequest.b (http://www.gamesnodie.com/template/js/jquery-1.11.1.min.js:1:90047)

Network tab results: http://prntscr.com/b1pao5网络标签结果: http : //prntscr.com/b1pao5

Please post in your question the JSON you are receiving from the server. 请在您的问题中发布您从服务器接收的JSON。

This issue could be related to a malformed JSON, or a wrong Header Content Type of your request, which actually should be as "application/json" as "Content-type" for JSON. 此问题可能与格式错误的JSON或请求的标题内容类型错误有关,对于JSON,实际上应将其作为“ application / json”与“ Content-type”。

I solved the issue by generating a recaptcha key and adding it to the config file. 我通过生成一个Recaptcha密钥并将其添加到配置文件中解决了该问题。 After that the problem got solved. 之后问题就解决了。

Define dataType json in your ajax call and then you don't need to use JSON.parse(). 在ajax调用中定义dataType json ,然后就不需要使用JSON.parse()了。

function redeem(){
    var code = $("#promocode").val();
    $.ajax({
        url:"/redeem?code="+code,
        dataType: 'json',
        success:function(data){     
            try{
                if(data.success){
                    bootbox.alert("Success! You've received "+data.credits+" credits.");                    
                }else{
                    bootbox.alert(data.error);
                }
            }catch(err){
                bootbox.alert("Javascript error: "+err);
            }
        },
        error:function(err){
            bootbox.alert("AJAX error: "+err);
        }
    });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SyntaxError:JSON.parse:JSON数据的第1行第1列出现意外字符吗? - SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data? 语法错误:JSON.parse:JSON 数据的第 1 行第 1 列出现意外字符 - SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data 语法错误json.parse json数据第1行第1列的意外字符 - syntaxerror json.parse unexpected character at line 1 column 1 of the json data SyntaxError:JSON.parse:JSON数据第3行第1列的意外字符 - SyntaxError: JSON.parse: unexpected character at line 3 column 1 of the JSON data SyntaxError:JSON.parse:JSON数据的第1行第2列出现意外字符 - SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data React SyntaxError:JSON.parse:JSON 数据第 1 行第 1 列的数据意外结束 - React SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data SyntaxError: JSON.parse: JSON 数据第 1 行第 1 列的数据意外结束 OK - SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data OK SyntaxError: JSON.parse: JSON 数据的第 1 行第 1 列的数据意外结束 - SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data 调用其余的WS并获取:SyntaxError:JSON.parse:JSON数据第1行第1列的数据意外结束 - Call a rest WS and get: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data SyntaxError:JSON.parse:JSON数据第1行第1列的数据意外结束[了解更多] - SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data[Learn More]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM