javascript - setTimeout giving unexpected identifier? - Stack Overflow

So I have this code that I am running inside of the google chrome console, and every time that I try to

So I have this code that I am running inside of the google chrome console, and every time that I try to run it it give me unexpected identifier on line: 12. I went to that line and it is the setTimeout. I really don't know how to fix this, I tried to just call snipebot() but that didn't work either.

function snipebot(itemID, max_price){
    var ItemURL = ".aspx?id=" + itemID;
            $.get(ItemURL, function(data){
                var purchaseData = $($(data).find(".PurchaseButton")[0]).data();
                        if (purchaseData['expectedPrice'] <= max_price){
                            $.post('/API/Item.ashx?rqtype=purchase&productID=' + purchaseData['productId'] + '&expectedCurrency=1&expectedPrice=' + purchaseData['expectedPrice'] + '&expectedSellerId=' + purchaseData['expectedSellerId'] + '&userAssetID=' + purchaseData['userassetId'], function(){
                            console.log('[' + purchaseData['expectedPrice'] + ']');
                            });
                        }
            }
            setTimeout(function(){
            snipebot(itemID, max_price);
            });
};
snipebot(18426536, 140);

So I have this code that I am running inside of the google chrome console, and every time that I try to run it it give me unexpected identifier on line: 12. I went to that line and it is the setTimeout. I really don't know how to fix this, I tried to just call snipebot() but that didn't work either.

function snipebot(itemID, max_price){
    var ItemURL = "http://www.roblox./Item.aspx?id=" + itemID;
            $.get(ItemURL, function(data){
                var purchaseData = $($(data).find(".PurchaseButton")[0]).data();
                        if (purchaseData['expectedPrice'] <= max_price){
                            $.post('/API/Item.ashx?rqtype=purchase&productID=' + purchaseData['productId'] + '&expectedCurrency=1&expectedPrice=' + purchaseData['expectedPrice'] + '&expectedSellerId=' + purchaseData['expectedSellerId'] + '&userAssetID=' + purchaseData['userassetId'], function(){
                            console.log('[' + purchaseData['expectedPrice'] + ']');
                            });
                        }
            }
            setTimeout(function(){
            snipebot(itemID, max_price);
            });
};
snipebot(18426536, 140);
Share Improve this question asked Apr 22, 2015 at 18:19 Devin FrancisDevin Francis 271 silver badge3 bronze badges 1
  • 1 It looks like you forgot to add the time interval for your setTimeout. – william.taylor.09 Commented Apr 22, 2015 at 18:22
Add a ment  | 

1 Answer 1

Reset to default 5

It's unexpected because your call to $.get hasn't been closed properly on the previous line:

function snipebot(itemID, max_price){
    var ItemURL = "http://www.roblox./Item.aspx?id=" + itemID;
            $.get(ItemURL, function(data){
                var purchaseData = $($(data).find(".PurchaseButton")[0]).data();
                        if (purchaseData['expectedPrice'] <= max_price){
                            $.post('/API/Item.ashx?rqtype=purchase&productID=' + purchaseData['productId'] + '&expectedCurrency=1&expectedPrice=' + purchaseData['expectedPrice'] + '&expectedSellerId=' + purchaseData['expectedSellerId'] + '&userAssetID=' + purchaseData['userassetId'], function(){
                            console.log('[' + purchaseData['expectedPrice'] + ']');
                            });
                        }
            }); // <-- here
            setTimeout(function(){
            snipebot(itemID, max_price);
            }, 2000); // <!-- See below
};
snipebot(18426536, 140);

Also note my second ment, where you've missed the 2nd parameter to setTimeout, namely how long to delay for. I've added in a two second delay as an example. Without this, it defaults to 0, which may or may not be what you intended.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744316705a4568219.html

相关推荐

  • javascript - setTimeout giving unexpected identifier? - Stack Overflow

    So I have this code that I am running inside of the google chrome console, and every time that I try to

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信