开发者

Unexpected token ILLEGAL javascript error in Google Chrome

开发者 https://www.devze.com 2022-12-18 22:58 出处:网络
I am getting a javascript (prototype.js) error: Unexpected token ILLEGAL at this line of code: newFriend = new friend(

I am getting a javascript (prototype.js) error: Unexpected token ILLEGAL at this line of code:

newFriend = new friend(
    response[0].@items[0]._id, 
    response[0].@items[0]._nickName, 
    response[0].@items[0]._profilePicture, 
    response[0].@items[0]._tagLine, 
    response[0].@items[0]._isInvite, 
  开发者_如何学编程  response[0].@items[0]._confirm
);

the response object looks like this:

[{
  "@type": "[Lcom.photoviewer.common.model.ThinUser;",
  "@items": [{
    "_id": "000.060318.05022007.00263.0067ur",
    "_nickName": "siraj",
    "_country": null,
    "_currentStorageLimit": 5000000000,
    "_currentStorage": 0,
    "_currentFileCount": 0,
    "_profilePicture": null,
    "_tagLine": null,
    "_membershipLevel": 0,
    "_isRejected": false,
    "_isInvite": false,
    "_confirm": false,
    "_verifiedOn": 1170716666000
  }]
}]

This is only happening in the Google Chrome browser and possibly other webkit browsers. It works fine in Firefox.


Try this instead:

newFriend = new friend(
    response[0]["@items"][0]._id, 
    response[0]["@items"][0]._nickName, 
    response[0]["@items"][0]._profilePicture, 
    response[0]["@items"][0]._tagLine, 
    response[0]["@items"][0]._isInvite, 
    response[0]["@items"][0]._confirm
);

I'm pretty sure @ is giving you a problem.

For weird characters it's always safer to use the ["@items"] notation instead of the (dot) notation .@items.


Property names containing @ and dot notation are incompatible in Chrome. Use square bracket notation instead (you already do when you construct the object).

0

精彩评论

暂无评论...
验证码 换一张
取 消