获取意外令牌非法 JS 错误
Getting Unexpected Token ILLEGAL JS Error
在页面上注册脚本后,我一直收到 "Unexpected Token ILLEGAL" 错误。
StringBuilder str = new StringBuilder();
str.Append("<script type='text/javascript'> function AnotherFunction(evt) { ");
str.Append("var xhr = new XMLHttpRequest();");
str.Append("var data = new FormData();");
str.Append("var files = $('#FileUpload1').get(0).files;");
str.Append("for (var i = 0; i < files.length; i++){");
str.Append("data.append(files[i].name, files[i]);}");
str.Append("xhr.upload.addEventListener('progress' , function (evt){");
str.Append("if (evt.lengthComputable) {");
str.Append(" var progress = Math.round(evt.loaded * 100 / evt.total);");
str.Append("$('#progressbar').progressbar('value', progress); }}, false);");
str.Append(" xhr.open('POST', 'Handler.ashx');");
str.Append("xhr.send(data); $('#progressbar').progressbar({");
str.Append(" max: 100,change: function (evt, ui){");
str.Append("$('#progresslabel').text($('#progressbar').progressbar('value') + '%');");
str.Append(" }, complete: function (evt, ui){");
str.Append(" $('#progresslabel').text('File upload successful!');' }});");
str.Append("evt.preventDefault(); }</script>");
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(this.GetType(), "RefreshParent", str.ToString(), false);
有人知道如何解决这个问题吗?
倒数第二个 str.Append() 调用中有一个额外的 '
。
改变
str.Append(" $('#progresslabel').text('File upload successful!');' }});");
到
str.Append(" $('#progresslabel').text('File upload successful!'); }});");
在页面上注册脚本后,我一直收到 "Unexpected Token ILLEGAL" 错误。
StringBuilder str = new StringBuilder();
str.Append("<script type='text/javascript'> function AnotherFunction(evt) { ");
str.Append("var xhr = new XMLHttpRequest();");
str.Append("var data = new FormData();");
str.Append("var files = $('#FileUpload1').get(0).files;");
str.Append("for (var i = 0; i < files.length; i++){");
str.Append("data.append(files[i].name, files[i]);}");
str.Append("xhr.upload.addEventListener('progress' , function (evt){");
str.Append("if (evt.lengthComputable) {");
str.Append(" var progress = Math.round(evt.loaded * 100 / evt.total);");
str.Append("$('#progressbar').progressbar('value', progress); }}, false);");
str.Append(" xhr.open('POST', 'Handler.ashx');");
str.Append("xhr.send(data); $('#progressbar').progressbar({");
str.Append(" max: 100,change: function (evt, ui){");
str.Append("$('#progresslabel').text($('#progressbar').progressbar('value') + '%');");
str.Append(" }, complete: function (evt, ui){");
str.Append(" $('#progresslabel').text('File upload successful!');' }});");
str.Append("evt.preventDefault(); }</script>");
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(this.GetType(), "RefreshParent", str.ToString(), false);
有人知道如何解决这个问题吗?
倒数第二个 str.Append() 调用中有一个额外的 '
。
改变
str.Append(" $('#progresslabel').text('File upload successful!');' }});");
到
str.Append(" $('#progresslabel').text('File upload successful!'); }});");