2

I have a page that executes a .get on the change of an HTML select:

$.get(link, function (data) {
    $("#divonpage").html(data);
});

The data obtained from the link contains a

$(document).ready(function () {
    ...code here...
});

in order to do things upon completion of the .get

On every browser except IE, this works with no problems.

With IE (even the latest version), this fails with a "$ is undefined" error, located at the $(document).

Apparently, all other browsers are able to use the jQuery loaded with the original page.

Thinking it may be a caching issue, I removed all headers that would prevent caching. This had no effect.

I am assuming that I will need to remove the $(document).ready and put this code to execute after the .get.

Any ideas?

I am using the latest version of jQuery, and I have tested older versions also.

urbz
  • 2,663
  • 1
  • 19
  • 29
  • 1
    It seems your IE does not pick up jQuery, have already tried using a CDN version or wrapping your jQuery code between `(function ($) { })(jQuery);` ? – MacK Aug 08 '14 at 11:53
  • Show the top part of your html where you implement jQuery and this script. – Dejan.S Aug 08 '14 at 11:54
  • `$(document).ready` is designed for the initial page load; I'm guessing that it simply doesn't get triggered again when loading additional HTML via AJAX in IE (jQuery tries to make document.ready work consisently across browsers, but there's no native document.ready event in Javascript so if you look in the jQuery source you'll see it's implemented differently for different browsers.) – Matt Browne Aug 08 '14 at 12:17
  • Isn't the onload event in the body tag equivalent to document.ready ? – RickInWestPalmBeach Aug 08 '14 at 12:31
  • Remove the code from the $(document).ready and executing it after the .get does not work either in IE, but works in all other browsers. I will be putting a disclaimer in the footer of my page to use IE at your peril. – RickInWestPalmBeach Aug 08 '14 at 12:38
  • 1
    No, not exactly...see http://stackoverflow.com/questions/4395780/difference-between-onload-and-ready – Matt Browne Aug 08 '14 at 12:40
  • Why not just change the code that's getting loaded via AJAX so it doesn't use document.ready? Just make sure the – Matt Browne Aug 08 '14 at 12:43
  • The page this is operating on uses JQuery Tabs, and each tab has its own $(document).ready. The first time this page loads, all is fine, even on IE. When I change the value of the HTML Select, every tab changes based on the selection, so multiple $(document).ready events are refired. This re-firing works fine in all browsers except IE. I will move the code to the bottom and see what happens, although I will probably have to de-JQuery the code first in order to avoid having the same issue. – RickInWestPalmBeach Aug 08 '14 at 14:08

0 Answers0