[英]SyntaxError: missing ; (semicolon) before statement - Razor
The block of code below triggers a SyntaxError
on a missing ;
下面的代码块在丢失时触发
SyntaxError
;
. 。 Here is a screenshot of Firebug's output:
这是Firebug输出的屏幕截图:
<script type="text/javascript">
$(document).ready(function () {
$("#SelectedMCO").change(function () {
var scheme = @Request.Url.Scheme.ToString();
var authority = @Request.Url.Authority.ToString();
var applicationPath = @Request.ApplicationPath.ToString();
var url = scheme + "://" + authority + applicationPath +"mytest/" + $("#Selectedoption").val();
$.getJSON(url, function (data) {
$("#Selectedsub").empty();
$.each(data, function(idx, obj) {
$('#SelectedSub').append('<option value="' + obj.EntityNumber +'">' + obj.Name + '</option>');
});
});
});
});
</script>
You just need to enclose your Razor variables in quotes: 您只需要将Razor变量括在引号中:
<script type="text/javascript">
$(document).ready(function () {
$("#SelectedMCO").change(function () {
var scheme = '@Request.Url.Scheme.ToString()';
var authority = '@Request.Url.Authority.ToString()';
var applicationPath = '@Request.ApplicationPath.ToString()';
var url = scheme + "://" + authority + applicationPath
+"mytest/" + $("#Selectedoption").val();
$.getJSON(url, function (data) {
$("#Selectedsub").empty();
$.each(data, function(idx, obj) {
$('#SelectedSub').append('<option value="' +
obj.EntityNumber +'">' + obj.Name + '</option>');
});
});
});
});
</script>
This will ensure that your variables will be interpreted as strings by the JavaScript interpreter. 这将确保您的变量将被JavaScript解释器解释为字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.