jquery - 加载时不引人注目的验证 javascript 错误 - $jQval 未定义

发布于 2024-12-17 17:39:44 字数 583 浏览 1 评论 0原文

我将其与 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>

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.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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风追烟花雨 2024-12-24 17:39:44

只是为其他从搜索中到达这里的人发帖...

在头部加载文件时出现错误的原因是 jquery.validate.unobtrusive 需要 jquery.validate。这就是导致错误的原因。

(即,仔细检查您是否在 jquery.validate.unobtrusive 之前成功包含 jquery.validate)

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. That's what was causing the error.

(ie, double-check that you're successfully including jquery.validate before jquery.validate.unobtrusive)

岁月无声 2024-12-24 17:39:44

已解决
级联 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,
                        });
                }
});

Solved
Cascading the ajax load calls solved it.. it looks like a timing issue on loading the two files

$.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,
                        });
                }
});
愛上了 2024-12-24 17:39:44

以下 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; }
}

The following 3 scripts work great for me:

<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; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文