4

In Visual Studio 2012 I created an MVC 4 project using the Internet template, when I then update jQuery to the current version of 1.9 I get a jQuery error when attempting to log in to the generated web application. This error only occurs in IE (I'm running IE 10) and appears to be due to differences in the JSON parsers across the different browsers.

So what I need to work out is, how can we use the MVC 4 Internet template and yet still be able to update to jQuery 1.9.

Here's the steps to repro the error;

1: Create a new MVC 4 project using the Internet project template - the template uses jQuery 1.7.1.1 and works fine, I can register as a new user and sign in etc.
2: Now update jQuery, jQuery validation and jQuery UI to the latest versions (currently 1.9.0, 1.10.0 and 1.10.0 respectively).
3: Run the app and switch to the sign in page. This page generates an error in the following jquery.unobtrusive-ajax.js code;

    $("a[data-ajax=true]").live("click", function (evt) {
    evt.preventDefault();
    asyncRequest(this, {
        url: this.href,
        type: "GET",
        data: []
    });
});


4: OK though, no problem, live() was removed in jQuery 1.9 so I include the jQuery migration script jquery-migrate-1.0.0.js.
5: I re-run the application and now get an error when I sign in parsing JSON in jquery-1.9.0.js. The error is in the parseJSON method;

    parseJSON: function( data ) {
    // Attempt to parse using the native JSON parser first
    if ( window.JSON && window.JSON.parse ) {
        return window.JSON.parse( data );
    }...

The error is caused by 'undefined' being passed to parseJSON and thus in IE window.JSON.parse throws an error where no error is thrown in other browsers.

So the question is, what would be an acceptable workaround to get the MVC 4 Internet template working with jQuery 1.9 on IE?

Incidentally, here's the partial parseJSON method from jQuery 1.8 which explains why there was no error previously.

    parseJSON: function( data ) {
    if ( !data || typeof data !== "string") {
        return null;
    }...
4

3 回答 3

1

JQuery has been deprecated a number of features. You might be interested in this:

https://github.com/jquery/jquery-migrate/#readme

于 2013-01-22T22:55:49.303 回答
1

The answer might be in this link. http://forum.jquery.com/topic/parsejson-in-1-9-0-is-different-from-earlier-versions It seems like the MVC team is planning to fix it in the next release. I hope this helps.

于 2013-01-23T15:24:44.957 回答
0

With ASP.NET and Web Tools 2012.2 release (download from http://www.asp.net/vnext), it should be fixed with an updated jquery.validate.unobtrusive.js.

于 2013-02-21T23:38:15.013 回答