Javascript Angular JS 不适用于 IE9,但适用于其他浏览器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26567729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 23:03:58  来源:igfitidea点击:

Angular JS not working with IE9 but works with other browsers

javascriptjqueryhtmlangularjsinternet-explorer

提问by Toni

So I am working on a small app that gets that from an API url like so... $http.get(s_url) .then(function(res) {... My app works well with chrome,safari,opera and firefox but displays a blank screen in IE9 Am I missing something in my html or js file? Here is what I have in my html file for IE...

所以我正在开发一个小应用程序,它从这样的 API url 中获取... $http.get(s_url) .then(function(res) {...我的应用程序适用于 chrome、safari、opera 和 firefox但在 IE9 中显示一个空白屏幕 我是不是在我的 html 或 js 文件中遗漏了什么?这是我在 IE 的 html 文件中的内容......

    <!--[if lte IE 8]>
    <script src="js/json2.js"></script>
    <script>
        document.createElement('ng-include');
        document.createElement('ng-pluralize');
        document.createElement('ng-view');
        document.createElement('x-restrict');
        document.createElement('x-fileupload');
        // Optionally these for CSS
        document.createElement('ng:include');
        document.createElement('ng:pluralize');
        document.createElement('ng:view');
        //customized tags
        document.createElement('location');
        document.createElement('temp');
        document.createElement('image');
        document.createElement('caption');
        document.createElement('temps');
        document.createElement('remtemps');
    </script>
    <![endif]-->
    <div ng-view></div>
</head>

回答by Srinivas Paila

Try prefixing ng-app and ng-view with data as in data-ng-app, data-ng-view.

尝试使用 data-ng-app、data-ng-view 中的数据作为前缀 ng-app 和 ng-view。

回答by JoSSte

I had a similar issue. The page would load properly, calling angular to populate a table. subsequent clicks on a refresh button should recall the fetching method, but were ignored by the browser.

我有一个类似的问题。页面将正确加载,调用 angular 来填充表格。随后单击刷新按钮应该会调用获取方法,但会被浏览器忽略。

The resolution was to add content expiry headers expiring 5 seconds in the past, and then IE would execute the Angular scripts.

解决方案是添加过去 5 秒过期的内容过期标头,然后 IE 将执行 Angular 脚本。

EDIT:

编辑:

How to implement

如何实施

The headers to add are specified in the HTTP specification.

要添加的标头在HTTP 规范中指定。

I have printed a fixed timestamp here. You can of course set the date explicitly using date/time functions

我在这里打印了一个固定的时间戳。您当然可以使用日期/时间函数显式设置日期

Depending on which language you are using, and which webserver yuo are hosted on, there are different ways to do this:

根据您使用的语言以及您托管的网络服务器,有不同的方法可以做到这一点:

.htaccess file:

.htaccess 文件:

<filesMatch "\.json">
   Header set Cache-Control "max-age=0, public"
   Header set Expires "Thu, 01 Dec 1994 16:00:00 GMT"
</filesMatch>

-note both shouldn't be necessary

-注意两者都不是必需的

if you are using php:

如果您使用的是 php:

<? header("Expires: Thu, 01 Dec 1994 16:00:00 GMT");
   header("Cache-Control: max-age=0, public");  
?>

if you are using jsp:

如果您使用的是jsp:

<% 
   response.setHeader("Cache-Control: max-age=0, public");
%>