I have开发者_运维知识库 an ASP MVC3 application that runs fine (in VS 2010 debug) in FireFox 4 but when I run the app in IE8 I get a bunch of JScript error in jquery-1.5.1 and jquery.validate.unobtrusive.
In my _SiteLayout.cshtml I am including the JavaScript like this:
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/QMSCommon.js")" type="text/javascript"></script>
...
<!--bottom of layout page - just before /body -->
@(Html.Telerik().ScriptRegistrar().jQuery(false).DefaultGroup(group => group.Combined(true).Compress(true)))
When I run this app in IE8 I get "Microsoft JScript runtime error: 'undefined' is null or not an object" in jquery.validate.unobtrusive.min.js right away. If I continue I get "Microsoft JScript runtime error: Object doesn't support this property or method" in JQuery-1-5-1.
Am I including the correct JS file - is the order correct (or significant)?
UPDATE:
I have isolated the problem to my Javascript (in QMSCommon.js). The entire contents of that file is here:
$(document).ready(function () {
//Make fields set to datePicker css class have a datepicker control
$('.datePicker').datepicker(
{ buttonImage: '/content/images/calendar_edit.png',
buttonImageOnly: true,
showOn: 'both'
});
});
If I comment out the datepicker portion my site works in IE8. Do you see anything with this code that IE8 doesn't like?
Ok, well this is a little embarrassing. The initial problem was due to the fact that I was not including the jquery-ui script :-). Firefox did not throw an error, IE did, but not at .datepicker rather somewhere deep within jQuery which was throwing me off. Anyway.
Furthermore I have updated my code to get the JQuery stuff from Google:
Works great.
I recommend using console.log statements to see why something is unexpectedly null. Check the debugger to look at the stacktrace. That might help. It's impossible from what you've shown to tell you more. But stepping through or using console statements to see where things deviate in Firefox or Chrome and IE8 will help you solve this issue.
One thing I've noticed is that IE 8 is much slower about rendering things so often when it's related to something null when it isn't in other browsers it might be because of an assumption about execution time. This may be an issue where you just need to defer JavaScript execution with a setTimeout or _.defer if you're using underscore.
If you run into more trouble just update the question or leave a comment.
精彩评论