The first line of code you show is invalid JavaScript:
var fileUploadDic = { 'firstname': 'Jo''hn', 'lastname' : 'Macy' , 'country' : 'USA };
Because the string 'Jo''hn'
cannot have single quotes in it. It must be either 'Jo\'hn'
or "Jo'hn"
. That is, if your JS string is quoted with single quotes, you need to avoid each quote character inside the backslash string, but if your JS string is quoted with double quotes, you can freely use singles within the string. If you need two single quotes in the string 'Jo\'\'hn'
or "Jo''hn"
.
You cannot fix anything in order to fix this client side, because being invalid, JavaScript will not work.
You must fix it on the server side; the easiest way is probably to avoid it with a backslash, noting that if it is in a C # line, you will also need to avoid a backslash so that the actual output to the browser contains a backslash:
"var fileUploadDic = { 'firstname': 'Jo\\'hn', 'lastname' : 'Macy' , 'country' : 'USA };"
source share