2013-01-16 30 views
29

Gần đây tôi đã nâng cấp một trang web để sử dụng ASP.NET MVC 4 và có mã sau đây để hiển thị gói xác thực jQuery của tôi.ASP.NET MVC 4 Mã xác nhận hợp lệ jQuery không hoạt động

Nhưng tôi nhận được lỗi sau:

Microsoft JScript runtime error: Object doesn't support property or method 'live' 

Và lỗi này khi nhấp vào một hộp văn bản:

Unhandled exception at line 1234, column 5 in http://localhost:13112/Scripts/jquery.validate.js 

0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'call': object is null or undefined 

My bó mã:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
        "~/Scripts/jquery.unobtrusive*", 
        "~/Scripts/jquery.validate*")); 

My _Layout.cshtml mã:

@Styles.Render("~/Content/css") 
    @Styles.Render("~/Content/themes/base/css") 
    @Scripts.Render("~/bundles/jquery") 
    @Scripts.Render("~/bundles/jqueryval") 
    @Scripts.Render("~/bundles/jqueryui") 
    @Scripts.Render("~/bundles/modernizr") 

Đây là HTML rendered tôi:

<link href="/Content/site.css" rel="stylesheet"/> 

     <link href="/Content/themes/base/jquery.ui.core.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.resizable.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.selectable.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.accordion.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.autocomplete.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.button.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.dialog.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.slider.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.tabs.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.datepicker.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.progressbar.css" rel="stylesheet"/> 
<link href="/Content/themes/base/jquery.ui.theme.css" rel="stylesheet"/> 

     <script src="/Scripts/jquery-1.9.0.js"></script> 

     <script src="/Scripts/jquery.unobtrusive-ajax.js"></script> 
<script src="/Scripts/jquery.validate.js"></script> 
<script src="/Scripts/jquery.validate.unobtrusive.js"></script> 

     <script src="/Scripts/jquery-ui-1.9.2.js"></script> 

     <script src="/Scripts/modernizr-2.6.2.js"></script> 

Ai đó có thể chỉ ra lý do tại sao lỗi này có thể xảy ra?

Cảm ơn, Alex.

+0

đã kiểm tra xem gói hàng/jquery có được hiển thị lần đầu không? Đảm bảo rằng nó được tải trước bất kỳ thư viện nào –

+0

Đã thêm HTML được hiển thị vào câu hỏi, bạn có thể thấy bất kỳ điều gì trong đó không? –

Trả lời

49

Phương thức .live đã không được chấp nhận trong jQuery v1.7 + và bị xóa trong jQuery v1.9 +.

cáo lỗi: http://bugs.jquery.com/ticket/13213
Giải thích: http://jquery.com/upgrade-guide/1.9/#live-removed

.live() removed

The .live() method has been deprecated since jQuery 1.7 and has been removed in 1.9. We recommend upgrading code to use the .on() method instead. To exactly match $("a.foo").live("click", fn), for example, you can write $(document).on("click", "a.foo", fn). For more information, see the .on() documentation. In the meantime, the jQuery Migrate plugin can be used to restore the .live() functionality.

Cách khắc phục: Tải jquery migrate plugin và thêm nó vào bó của bạn:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
       "~/Scripts/jquery-{version}.js", 
       "~/Scripts/jquery-migrate-{version}.js")); 

Cập nhật: Plugin Migrate bây giờ đã có từ Nuget:

PM> Install-Package jQuery.Migrate

+0

Ah nó đang thêm rằng, đã không nhận thức được rằng nó không nên có. Tuy nhiên tôi nhận được một lỗi khác (thêm vào câu hỏi), bạn có thể cho tôi biết điều gì đang gây ra nó không? –

+0

Đã cập nhật câu trả lời. –

+0

O không được thêm thủ công, đó là kết quả của Scripts.Render() –

Các vấn đề liên quan