简体   繁体   English

不知道如何调试类似的东西:Uncaught SyntaxError: Unexpected token [

[英]Not sure how to debug something like: Uncaught SyntaxError: Unexpected token [

So I know this is a topic that always gets downvoted no matter what.所以我知道这是一个无论如何都会被否决的话题。 But I have this page and it used to work fine.但我有这个页面,它曾经工作得很好。 I don't know what happened but one day it says:我不知道发生了什么,但有一天它说:

Uncaught SyntaxError: Unexpected token [

While this is part of my JS object, and it always worked fine.虽然这是我的 JS 对象的一部分,但它始终运行良好。 I've gone over all my code to see if I didn't forget any brackets or semicolons, but I can find nothing...我已经检查了我所有的代码,看看我是否没有忘记任何括号或分号,但我什么也找不到......

Can someone just advice me on how to debug something like this?有人可以建议我如何调试这样的东西吗? Cheers!干杯!

Here's my JS function until the error.这是我的 JS 函数,直到出现错误。 The error is shown even before the console.log happens which is written above it!该错误甚至在上面写的 console.log 发生之前就显示出来了! How weird is that!这是多么奇怪啊!

fill_grid_json = function(jsonData, result_count){

p_num = parseInt($("#p_num").val());
item_num = parseInt($("#item_num").val());
if(isNaN(item_num)){
    item_num = 20;
}
console.log("m p_num: "+p_num);
console.log("m item_num: "+item_num);

    /*=================\
    |   Calculate Pages |
    \=================*/

calculatePages(result_count,p_num,item_num);

// Calculate item range 
var toItemX = item_num*p_num;
var fromItemX = toItemX-item_num;

if(toItemX>result_count){
    toItemX = result_count;
}
console.log("item range: "+(fromItemX+1)+"-"+toItemX+" / "+result_count);

//Item amount etc.
var hitNum = "<span>"+(fromItemX+1)+"-"+toItemX+" / "+result_count+"</span><span class='item_unit'>items</span>";
$(".hit_num").html(hitNum);




var gridItems = []; // Grid Items container array
$.each(jsonData, function(i) {
if(jsonData[i].img_src!=null && jsonData[i].img_src!=""){

    // get JS variables
    var id = jsonData[i].ID;
    var post_title = jsonData[i].post_title;
    var supplier_company = jsonData[i].supplier_company;
    var img_src = jsonData[i].img_src[0];
    var tags = jsonData[i].tags;
    var post_meta = jsonData[i].post_meta;

      //``````````````````````//
     //     MAKE THE GRID ITEM 
    //,,,,,,,,,,,,,,,,,,,,,,//

/*******************
    Make the necessary pieces    
********************/

// Add GP Incentive
var post_meta['exw_from_usd'] = GPincentive(post_meta['exw_from_usd']);
var post_meta['exw_to_usd'] = GPincentive(post_meta['exw_to_usd']);     

There at the very end: post_meta['exw_from_usd'] it bugs.最后是: post_meta['exw_from_usd']它有问题。 However, this used to never be a problem and always worked... So i'm really confused.然而,这曾经从来都不是问题并且总是有效......所以我真的很困惑。

You clearly have changed it, because this is invalid code:您显然已经更改了它,因为这是无效代码:

var post_meta['exw_from_usd'] = GPincentive(post_meta['exw_from_usd']);

It's valid without the var at the beginning.它在开头没有var的情况下有效。 With the var it's invalid and always has been.使用var它是无效的,并且一直都是。

I suppose it's possible that you used to visit with a browser whose JavaScript engine ignored the error before, but...我想您可能曾经使用浏览器访问过其 JavaScript 引擎之前忽略了该错误,但是...

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

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