Javascript parse error on '\u2028' unicode character

后端 未结 4 1164
南笙
南笙 2020-11-30 21:12

Whenever I use the \\u2028 character literal in my javascript source with the content type set to \"text/html; charset=utf-8\" I get a javascript parse errors.

Examp

4条回答
  •  攒了一身酷
    2020-11-30 21:48

    Alright,to answer my own question.

    Normally a JSON parser strips out these problem characters, because I was retrieving JSONP I wasn't using a JSON parser, in stead the browser tried to parse the JSON itself as soon as the callback was called.

    The only way to fix it was to make sure the server never returns these characters when requesting a JSONP resource.

    p.s. My question was about u2028, according to Douglas Crockford's json2 library all of the following characters can cause these problems:

    '\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff'

提交回复
热议问题