错误消息“未终止的字符串文字" [英] Error message "Unterminated string literal"

查看:669
本文介绍了错误消息“未终止的字符串文字"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery来输出PHP从数据库中创建的JSON字符串的结果,

I'm using jQuery to output the results of a JSON string created by PHP from a database,

唯一的问题是某些数据位于多行上...我该如何解决这会导致JavaScript中的字符串文字错误无限终止?

The only problem is that some of the data is on multiple lines... How would I get around this causing an unterminated string literal error in JavaScript?

推荐答案

通过用"\\ n"替换"\ n"并用"\\ r"替换"\ r"来换码.您还需要转义单引号或双引号,具体取决于您用来定界字符串的方式.

Escape line endings by replacing "\n" with "\\n" and "\r" with "\\r". You will also want to escape single or double quotes, depending on which you are using to delimit the string.

这篇关于错误消息“未终止的字符串文字"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆