2017-09-01 22 views
0

我有一个简单的HTML文件与调用Web服务的jQuery脚本。在Internet Explorer中的jQuery错误 - 对象不支持属性或方法'addEventListener'发生

<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> 

在Chrome中一切正常,但当我尝试在Internet Explorer 9中打开它时失败。当我调试我发现这个错误:

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 

任何帮助表示赞赏。

+1

@AlonEitan也许我误解,但根据jQuery的[浏览器支持(https://jquery.com/browser-support/)这不是说目前的版本应该在IE 9+中工作吗? – Santi

+1

哦,所以我感到困惑与ie8然后,感谢您让我知道 –

+0

您的代码中没有创建一个事件侦听器,我不明白为什么它会遇到该错误。 – Barmar

回答

1

您的HTML文档没有doctype声明。这是IE9需要包括addEventListener。没有它,你会陷入怪癖模式,事情不会像你期望的那样行事。

在HTML的顶部将这个:

<!DOCTYPE html> 
+0

删除了错误,谢谢! – Ram

+0

不客气。 – spanky

相关问题