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

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

问题描述

我正在使用 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天全站免登陆