簡體   English   中英

jQuery意外令牌錯誤

[英]jQuery unexpected token error

我收到此錯誤: Uncaught SyntaxError: Unexpected Token

這是我的代碼:

$(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");
            }       

         });

}

這是jquery.min.js的最后一行

錯誤似乎與json = eval("(" + msg2 + ")");

任何想法如何解決這個問題?

這不是有效的JSON。 應該為json = eval("{" + msg2 + "}"); JSON對象。

您發現的錯誤是正確的。

要制作JSON對象,您應該使用“ {”而不是“(”

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM