unobtrusive validation javascript error on load - $jQval is
unobtrusive validation javascript error on load - $jQval is undefined
我使用jquery 1.7。我一直得到- jQval is undefined
错误。
这是我如何加载脚本。
$.ajax({
url: "http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.js",
dataType: "script",
cache: true,
success: callback
});
我也试过直接在头部加载它-同样的错误
<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>
只是发布给其他人从搜索到这里…
在头部加载文件时出现错误的原因是jquery.validate.unobtrusive需要jquery.validate。这就是导致错误的原因。
(即,仔细检查是否成功地包含了jquery。
已解决层叠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,
});
}
});
以下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>
假设你有一个表单:
@using (Html.BeginForm())
{
@Html.EditorFor(x => x.Foo)
@Html.ValidationMessageFor(x => x.Foo)
<button type="submit">OK</button>
}
输入到视图模型:
public class MyViewModel
{
[Required]
public string Foo { get; set; }
}
相关文章:
- Is onfling available for html, html5
- jQuery is not loaded
- reactRedux is not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Jquery - table.row(tr) is undefined
- contentWindow.document.body is null
- Tomcat websocket is not working
- noty.js is returning undefined
- $routeParams is undefined
- NodeJS Multer is not working
- React, Webpack: bundle.js is not generated
- jQuery is not defined - WordPress footer.php
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- imageArray[i] = imageItem is incompatible
- GAPI Is Not Defined
- Angular2 rc1, where is shims_for_IE
- Is (!~index) faster than (index === -1)?
- Mouse Out Orange Div "CurrentHeight" is not applyi
- Is jquery's attr() asynchronous?
- unobtrusive validation javascript error on load - $jQval is