admin管理员组文章数量:1278880
I am using this with jquery 1.7. I keep getting - jQval is undefined
error.
This is how i am loading the script.
$.ajax({
url: ".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=".7/jquery.min.js"></script>
<script src=".0/jquery.validate.unobtrusive.js" type="text/javascript"></script>
I am using this with jquery 1.7. I keep getting - jQval is undefined
error.
This is how i am loading the script.
$.ajax({
url: "http://ajax.aspnetcdn./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./ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn./ajax/mvc/3.0/jquery.validate.unobtrusive.js" type="text/javascript"></script>
Share
Improve this question
edited Nov 23, 2011 at 21:37
Rob W
349k87 gold badges807 silver badges682 bronze badges
asked Nov 23, 2011 at 21:33
MoXplodMoXplod
3,8526 gold badges39 silver badges47 bronze badges
2
-
I don't suppose removing the back tick from before
type=
does anything, does it? – Richard Marskell - Drackir Commented Nov 23, 2011 at 21:36 - sorry that was just a typo in the question – MoXplod Commented Nov 23, 2011 at 21:37
3 Answers
Reset to default 9Just 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. That's what was causing the error.
(ie, double-check that you're successfully including jquery.validate before jquery.validate.unobtrusive)
Solved Cascading the ajax load calls solved it.. it looks like a timing issue on loading the two files
$.ajax({
url: "http://ajax.aspnetcdn./ajax/jquery.validate/1.8.1/jquery.validate.min.js",
dataType: "script",
cache: true,
success: function () {
$.ajax({
url: "http://ajax.aspnetcdn./ajax/mvc/3.0/jquery.validate.unobtrusive.js",
dataType: "script",
cache: true,
});
}
});
The following 3 scripts work great for me:
<script src="http://ajax.googleapis./ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn./ajax/jquery.validate/1.9/jquery.validate.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn./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; }
}
本文标签: jqueryunobtrusive validation javascript error on loadjQval is undefinedStack Overflow
版权声明:本文标题:jquery - unobtrusive validation javascript error on load - $jQval is undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741299756a2371025.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论