仅 IE 9 出现未终止字符串常量错误
unterminated string constant error only with IE 9
好的,我在IE 8和9中遇到了此错误,这是Ajax调用
$('#$id').ajaxForm({
beforeSend: function() {
$("#{$this->name}_div").hide();
$("#{$this->name}_message").hide();
$("#{$this->name}_message").show().html('<img src="$gif">');
},
success: function(response)
{
var response = JSON.parse(response);
if (response.error != 'undefined')
{
...
}
}
问题出在这一行 JavaScript 代码中
var response = JSON.parse(response);
我的Javescript坏了,脚本可以在浏览器和Internet Explorer 10中工作,我担心是否有较旧的IE的人尝试访问我的网站。这个错误有什么解决方案吗?
你为什么要尝试自己解析JSON? ajaxForm
为此提供了一个dataType
选项:
$('#$id').ajaxForm({
beforeSend: function() {
$("#{$this->name}_div").hide();
$("#{$this->name}_message").hide();
$("#{$this->name}_message").show().html('<img src="$gif">');
},
dataType: 'json',
success: function(response){
if (response.error != 'undefined') {
...
}
}
});
另一方面,如果您的JSON中存在其他浏览器恰好容忍的无效内容,那么几乎唯一的答案就是修复您的JSON。
相关文章:
- JavaScript 中数据库数据的未终止字符串文字
- 换行符导致 JavaScript 中的错误“未终止字符串文字”
- Javascript 代码上的未终止字符串常量
- 仅 IE 9 出现未终止字符串常量错误
- MVC - 处理新行的未终止字符串文本
- Salesforce JavaScript未终止字符串常量错误
- 带有if-else的未终止字符串常量
- 语法错误未终止字符串文本jquery
- jquery附加了很多html(得到“未终止字符串文字”或“错误转义”错误)
- 使用javascript存储动态内容时,未终止字符串文本错误
- 奇怪的未终止字符串文本错误与Firefox
- SyntaxError:未终止字符串文本var address = "
- Firebug中的未终止字符串文本错误
- 线程“main”中的异常webdriverexception:未终止字符串字面值
- 撇号终止字符串,导致脚本无法工作
- 添加由于未终止字符串常量错误而无法工作的行
- SyntaxError:未终止字符串字面值(下划线模板)
- SyntaxError:未终止字符串字面值
- 如何修复JS '未终止字符串literal'错误
- IE10(在兼容模式下)在有效代码上生成SCRIPT1015:未终止字符串常量错误