【问题标题】:Loading JSON via Angular Service fails in IE9在 IE9 中通过 Angular 服务加载 JSON 失败
【发布时间】:2015-05-19 23:31:57
【问题描述】:

在我看来,我正在通过 AngularJS 服务加载一些数据。这适用于现代浏览器,但在 Internet Explorer 9 及更低版本中非常失败。当我调用返回(通常)JSON 之类的控制器时

[{"id":2,"title":"Product","slug":"product","short_description"...}]

正在 IE9 中打开“保存”对话框。因此,服务中的调用返回当前 HTML 站点的标记。看起来像这样:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        ...

控制器中的方法调用如下所示:

Product.get()
    .success(function(data) {
        $scope.products = data;
        $scope.loading = false;
    })
    .error(function(msg) {
        $log.error(msg);
    });

Product.get()-Service 基本上就是$http.get('http://localhost:8000/api/products')

更新:this.JSON 返回 false...您能建议一个解决方法吗?

提前致谢!

【问题讨论】:

    标签: json angularjs internet-explorer-9


    【解决方案1】:

    IE9 在解析 json 时比现代浏览器挑剔得多。

    可能是您需要在服务器上序列化 HTML 时对其进行转义。

    以 C# 为例,这可以通过 Newtonsoft 的 StringEscapeHandling.EscapeHtml (http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_StringEscapeHandling.htm)

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      相关资源
      最近更新 更多