[英]jquery - unobtrusive validation javascript error on load - $jQval is undefined
I am using this with jquery 1.7. 我在jquery 1.7中使用它。 I keep getting -
jQval is undefined
error. 我一直在 -
jQval is undefined
错误。
This is how i am loading the script. 这是我加载脚本的方式。
$.ajax({
url: "http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.js",
dataType: "script",
cache: true,
success: callback
});
I also tried loading it directly in the head - same error 我也尝试将它直接加载到头部 - 同样的错误
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.js" type="text/javascript"></script>
Just posting for anyone else getting here from a search... 只是发布给搜索到这里的其他人...
The reason you were getting the error when loading the files in the head is that jquery.validate.unobtrusive requires jquery.validate. 在头部加载文件时出现错误的原因是jquery.validate.unobtrusive需要jquery.validate。 That's what was causing the error.
这就是导致错误的原因。
(ie, double-check that you're successfully including jquery.validate before jquery.validate.unobtrusive) (即仔细检查您是否在jquery.validate.unobtrusive之前成功包含了jquery.validate)
Solved Cascading the ajax load calls solved it.. it looks like a timing issue on loading the two files 解决了级联ajax加载调用解决了它...它看起来像加载这两个文件的时间问题
$.ajax({
url: "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js",
dataType: "script",
cache: true,
success: function () {
$.ajax({
url: "http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.js",
dataType: "script",
cache: true,
});
}
});
The following 3 scripts work great for me: 以下3个脚本对我很有用:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.js" type="text/javascript"></script>
Assuming you have a form: 假设你有一个表格:
@using (Html.BeginForm())
{
@Html.EditorFor(x => x.Foo)
@Html.ValidationMessageFor(x => x.Foo)
<button type="submit">OK</button>
}
typed to a view model: 键入视图模型:
public class MyViewModel
{
[Required]
public string Foo { get; set; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.