unterminated string literal

淺唱寂寞╮ 提交于 2019-12-24 01:58:11

问题


I have a php-script, which uploads mp3-files on my server. I use 'uploadify' for it. There is an event 'onSelect'(documentation), which called when file has been uploaded. Using it I want to refresh playlist dynamically after each file's uploading.

But my function from 'onselect' field throws an error 'unterminated string literal'. After long searching I make my one-line function instead multi-line(breaklines have been added here for the convenience) and add slashes before double quotes.

function() {$('#response').append("
<script type=\"text/javascript\">
    var flashvars = {url:'./media/audio/users/126/md6xs4cv8ks0.mp3',artist:'Undef', track:'Undef', duration:''};
    var Params = {};
    var attributes = {};
    swfobject.embedSWF(\"min.swf\", \"myAlternativeContent1\", \"320\", \"40\", \"9.0.0\", false, flashvars, params, attributes);
</script>
<div id="myAlternativeContent1">
    <a href="http://www.adobe.com/go/getflashplayer">
    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
    </a>
</div>

回答1:


Contrary to the other answers, string literals can contain line breaks, they just need to be escaped with a backslash like so:

var string = "hello\
world!";

However, this does not create a line break in the string, as it must be an explicit \n escape sequence. This would technically become helloworld. Doing

var string = "hello"
+ "world"

would be much cleaner




回答2:


The syntax highlighting right there in your post makes it clear: you have unescaped quotes in your <div> block (and you forgot the end of your script).

Anyway, string literals in Javascript can't span multiple lines.

Instead of:

alert("lol
       wtf");

write:

alert("lol" +
      "wtf");

You might also consider breaking apart the </script> substring, which has been known to cause parsing problems:

"</scr" + "ipt>"

(Strictly speaking, to be equivalent, the second example above would have a \n and some spaces after lol, but that shouldn't matter in your case of writing HTML markup.)




回答3:


Could be the presence of the </script>. Try escaping one or more of those characters (i.e. use <\/script> instead)



来源:https://stackoverflow.com/questions/6876264/unterminated-string-literal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!