当脚本在页面上注册后,我在脚本上不断收到"意外令牌非法"错误。
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!'); }});");