0

I have a simple HTML file with jQuery script calling a web service.

<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type="text/javascript"> function makeRequest(url, messageString) { return $.ajax({ url, headers: { 'Authorization': 'Bearer XXXXX', 'Content-Type': 'application/json' }, method: 'POST', dataType: 'json', data: messageString, }); } function request1() { var messageString = '{"data":{"sample_data":"4.40%"}}'; const url = 'https://url/v1/projects/path/results'; return makeRequest(url, messageString); } $.when(request1()) .then(function (data1) { $('#level1').html(data1[0].data.content); }); </script> </head> <body> <div id="level1"></div> </body> </html> 

Everything works fine in Chrome but when I try to open it in Internet Explorer 9 it fails. When I debug I found this error:

Unhandled exception at line 3, column 147 in https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js 0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'addEventListener' occurred 

Any help appreciated.

8
  • 1
    @AlonEitan Perhaps I'm misunderstanding, but according to jQuery's Browser Support, does this not say that the current version should work in IE 9+? Commented Sep 1, 2017 at 19:19
  • 1
    Oh, so I got confused with ie8 then, thanks for letting me know Commented Sep 1, 2017 at 19:20
  • 1
    Open the console, and check, that you're really running the page in IE9 mode. Commented Sep 1, 2017 at 19:20
  • 1
    First thing I look at when I'm getting unexpected IE incompatibility issues is Compatibility Mode. If necessary, you can read this for a bit more information. Commented Sep 1, 2017 at 19:22
  • 1
    @AlonEitan: That's new shorthand syntax that lets you elide a property name that matches the variable name that holds the value. var url = "foo"; var obj = {url, bar: "baz"}; // {url: "foo", bar: "baz"} Commented Sep 1, 2017 at 20:29

1 Answer 1

2

Your HTML document doesn't have a doctype declaration. This is needed for IE9 to include addEventListener. Without it, you're in quirks mode, and things will not behave as you'd expect.

Put this at the top of your HTML:

<!DOCTYPE html> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.