简体   繁体   中英

unterminated string constant error in serialized json string

I need to send a serialized data as parameter in a javascript function as shown below.

<input type="button" id="btn1" onclick="fncname('{"data":"testval"}';)">

I am getting error unterminated string constant.

Can anyone help me to find out a solution for this?

You'll have to html encode your attribute to avoid conflicting quotes.

<input type="button" id="btn1" onclick="fncname('{&quot;data&quot;:&quot;testval&quot;}')">

http://jsfiddle.net/3ZbYR/

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