Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery AJAX not working in IE9

Tags:

jquery

ajax

I am writing an ajax web application but for whatever reason when I perform a GET against an internal data service in Internet Explorer 9 (IE9) it does not work. This same call works perfectly fine in Chrome, Firefox and Safari. I am using a localhost web server (wamp) for development and developing on the same network as the data service I am trying to hit. I am using Jquery 1.8.1 (I have gone back a few versions but still see the problem). My code looks like this:

$(document).ready(function() {

                    var loginUrl = "http://omittedurl.com";
                    console.log(loginUrl);
                    $.ajax({
                        type : "GET",
                        url : loginUrl,
                        dataType : "json",
                        success : function(response) {
                            console.log("RESPONSE: " + response);

                        }
                    });
            });

As I stated before this code works fine on Chrome and Firefox. In IE9 when I look at the web debugger there are no errors in the logs. It is like IE9 is just complete ignoring the .ajax chunk. Things I have tried:

  • Turn Ajax Caching Off
  • URL encoded my request URL
  • Went back to three older versions of Jquery
  • Manually pinged my URL from IE9 (able to get a response)

Any ideas??

like image 590
Kevin Avatar asked Sep 25 '12 22:09

Kevin


1 Answers

Look's like its a problem with

console.log()

IE has no console object when Developer tools is not open.. Try running your code by commenting your console.log and try again..

$(document).ready(function () {

    var loginUrl = "http://omittedurl.com";
    //console.log(loginUrl);
    $.ajax({
        type: "GET",
        url: loginUrl,
        dataType: "json",
        success: function (response) {
           // console.log("RESPONSE: " + response);
           alert("RESPONSE: " + response)
        }
    });
});

If you want to use console , you need to define that first if Developer tool's is not open..

if (typeof console === "undefined" || typeof console.log === "undefined") {
     console = {};
like image 141
Sushanth -- Avatar answered Sep 28 '22 07:09

Sushanth --