简体   繁体   English

jQuery意外令牌错误

[英]jQuery unexpected token error

I am getting this error: Uncaught SyntaxError: Unexpected Token 我收到此错误: Uncaught SyntaxError: Unexpected Token

This is my code: 这是我的代码:

$(document).ready(function(){ 

$(".cartsummary .showcartsumm").click(function() {
  $(".cartsummary .cartitems").show();    
});
$(".cartsummary").hoverIntent(
function () {
 $(".cartsummary .cartitems").fadeIn();
}, 
function () {
   $(".cartsummary .cartitems").fadeOut();
}) 
nutrishowcart(0);
});

function nutrishowcart(slidedown)
{
    $.ajax({
            type: "POST",
            url: "/CUSTminicart.aspx" + "/" + "Render",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "text",
            success: function(msg) { 
                // msg2 = eval(msg);
                // Get rid of the copyright text that kills JSON
                index = msg.indexOf('<div align="center">');
                msg2 = msg.slice(0,index);
                //msg2 = msg;
                json = eval("(" + msg2 + ")");
                $("#cartwrapper").html(json.d);

                if (slidedown==1) {
                    $(".cartsummary .cartitems").fadeIn().delay(2000).fadeOut();
                }
            },
            error:function (xhr, ajaxOptions, thrownError){
            alert("Minicart issue");
            }       

         });

}

This is on the last line in jquery.min.js 这是jquery.min.js的最后一行

The error seems to be with json = eval("(" + msg2 + ")"); 错误似乎与json = eval("(" + msg2 + ")");

Any ideas how to resolve this? 任何想法如何解决这个问题?

This isn't valid JSON. 这不是有效的JSON。 It should be json = eval("{" + msg2 + "}"); 应该为json = eval("{" + msg2 + "}"); for a JSON object. JSON对象。

The error you spotted out is right. 您发现的错误是正确的。

To make JSON object you should use "{" instead of "(" 要制作JSON对象,您应该使用“ {”而不是“(”

json = eval("{" + msg2 + "}");

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM