简体   繁体   中英

Uncaught SyntaxError: Unexpected token & due to &quot error

I am passing a JSON object to Javascript from Python which is a set of dates queried via SQLAlchemy from MySQL.

The set of dates has been formatted using

datetime.datetime.strftime(r,"%Y-%m-%dT%H:%M:%S.%f%z")

to look as follows:

["2008-01-31T00:00:00.000000", "2008-02-29T00:00:00.000000", "2008-03- 
 31T00:00:00.000000"]

but they come through as:

["2008-01-31T00:00:00.000000", "2008-02-29T00:00:00.000000", "2008-03-31T00:00:00.000000"]

and I then get the syntax error.

I have tried:

var dates = ({{dates}}).replace(/"/g, '\\"'); 

however this has no effect. I need to be able to pass this set of dates to a chart in ChartJS.

Try it below ::

""2008-01-31T00:00:00.000000"".replace(/"/gi,'\\"');

other wise data sending time service to replace respective format

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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