HTML/XML中的JavaScript:格式不正确错误
我试图从JSON中获取信息,但得到一个错误,即我的XML格式不正确。它指向HTML/XML中的JavaScript:格式不正确错误,javascript,html,json,xml,hbbtv,Javascript,Html,Json,Xml,Hbbtv,我试图从JSON中获取信息,但得到一个错误,即我的XML格式不正确。它指向 if((jsonResponse[0].error) && (jsonResponse[0].error.type == 101)) { ----------------------------^ 以下是上下文: <?xml version="1.0" encoding="UTF-8" ?> <!--As DOCTYPE either the strict XHTML declara
if((jsonResponse[0].error) && (jsonResponse[0].error.type == 101)) {
----------------------------^
以下是上下文:
<?xml version="1.0" encoding="UTF-8" ?>
<!--As DOCTYPE either the strict XHTML declaration or
"-//HbbTV//1.1.1//EN" "http://www.hbbtv.org/dtd/HbbTV-1.1.1.dtd"
shall be used as described in the HbbTV-standard: A.2.6.2.-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--Required XML-namespace as described in the HbbTV-standard: A.2.6.2.-->
<html xmlns="http://www.w3.org/1999/xhtml">
将JavaScript包装在
CDATA
部分,这样&
就不会被解释为标记:
<script>
<![CDATA[
JaveScript code here
]]>
</script>
更好的解决方案是将脚本代码移出到单独的文件中,并使用src属性定义路径,这样就不需要再使用cdata
并且注意Javascript不包含字符串]>
。