0

I having a issue while bundling by JavaScript files through Bundling in .NET MVC4

I am adding following scripts to bundle up in my code

bundles.Add(new ScriptBundle("~/bundle").Include("~/Scripts/jquery-1.9.1.min.js","~/Scripts/kui/kendo.all.min.js", "~/Scripts/kui/kendo.grid.min.js", "~/Scripts/jquery.validate.min.js"));

Everything works fine till here, but When I Add jquery.unobtrusive-ajax.min.js to the list:

bundles.Add(new ScriptBundle("~/bundle ").Include("~/Scripts/jquery-1.9.1.min.js","~/Scripts/jquery.unobtrusive-ajax.min.js","~/Scripts/kui/kendo.all.min.js", "~/Scripts/kui/kendo.grid.min.js", "~/Scripts/jquery.validate.min.js"));

All scripts stops working (Validation, Kendo UI etc.) and I get this exception through Visual Studio JS debugger: Microsoft JScript runtime error: Object doesn't support this property or method

With below code highlighted in the generated bundles script file:

n("a[data-ajax=true]").live("click",function(n){n.preventDefault(),r(this,{url:this.href,type:"GET",data:[]})}),n("form[data-ajax=true] input[type=image]").live( ….

And on moving forward nothing (JavaScript/Jquery related) works anymore.

Probably there is conflict in JS file with var or function names? But it’s very hard to trace out in a long minified and bundled script file. Kindly help.

SajjadHashmi
  • 3,795
  • 2
  • 19
  • 22

2 Answers2

1

It is because the live function has been REMOVED in jQuery v1.9.

You can try changing .live to .on.

Or, try to update the jQuery Unobtrusive Ajax NuGet package.

Corneliu
  • 2,932
  • 1
  • 19
  • 22
  • The latest version on NuGet is `2.0.20710.0` last updated on `August 11, 2012` which is way prior to the jQuery v1.9 release so i don't think updating it would work? – SajjadHashmi Apr 02 '13 at 18:30
  • @SajjadHashmi I've just tested updating jQuery Unobtrusive Ajax NuGet package on a test MVC 4 project, and it works. The new version is 2.0.30116.0 and it's been updated on Feb 18, 2013. It uses the .on function. – Corneliu Apr 03 '13 at 08:46
1

Try like this:

replace

$("a[data-ajax=true]").live("click",function(n){});

with

$("a[data-ajax=true]").on("click",function(n){});

Hope it helps

Karthik Chintala
  • 5,465
  • 5
  • 30
  • 60