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
Add a ment  | 

3 Answers 3

Reset to default 9

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)

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