jQuery 1.5, jquery.validate and Ajax/getJSON

Apparently, the new version of jQuery conflicts with the version of the jquery.validate plugin that is included with Microsoft’s MVC 3 template. After a frustrating hour of debugging and using Fiddler (as I didn’t realize the problem was related to a plugin I wasn’t actively using on the web page), I stumbled into the answer/workaround on github here.

The specific issue that I encountered was what I thought was a simple use of the ajax method of jQuery:

    url: _fullRoute + "/Fetch",
    data: { since: this._lastRefresh },
    type: "get",            
    dataType: "json"
}).success(function (data) { alert("success"); }).
        error(function (e) { alert("error: " + e.toString()); }).
        complete(function () { alert("complete"); });

I’d tried lots of things, experimented with what seemed like countless JsonResult options (along with Json function call changes), and nothing worked. The JavaScript error callback function would always be called. The error: parseerror. Arrgh.

return Json(new { result = “why me!?” }, "application/json", JsonRequestBehavior.AllowGet);

Thankfully, a user on github, jfirebaugh, took the time to resolve the issue and produced a patch (change here).

You can look at the details on github.

After applying the patch, and using the Microsoft Ajax Minifier, I noticed that the file was about 4K smaller than the one that is included with the MVC 3 template. Smile


One Comment

  1. Since you’ve been through this: Which steps do I need to take to upgrade to jQuery 1.5 in my MVC3 project? Care to fill me in a bit about which files you replaced etc? Thanks.

Comments are closed.