4

这段代码可以在 Chrome、FF 上运行,但不能在 Internet Explorer 上运行!它只是一个简单的 JSON 文件调用,获取数据,并显示到 HTML 网页。看看下面:

$.ajax({
              type: "GET",
              url: "shop.json",
              cache: false,
              data: "{}",
              success: function(jd) {
                $.each(jd.lots, function(i,f){
                  if(f.shop.category != "PARKING")
                  {
                    if(jQuery.inArray(f.shop.category, categoryArray) == -1) //not in array
                    {
                      categoryArray.push(f.shop.category);
                     $('#tenant-list').append('<table width="100%" class="tenantList" id="' +jQuery.inArray(f.shop.category, categoryArray) + '"><th class="title" style="background-color: orange;" colspan="3">'+f.shop.category+'</th>');
                      $('.categoryList').append('<tr><td><a class="categoryListAnchor" style="color: #666666;text-decoration: none;" href="#'+jQuery.inArray(f.shop.category, categoryArray)+'">'+f.shop.category+'</td></tr>');
                    }
                    $('#'+jQuery.inArray(f.shop.category, categoryArray)).append('<tr><td class="shopName" width="500px;">' + f.shop.name + '</td><td><img src="images/'+f.zone+'.jpg"></td><td>' +f.floor + '</td></tr></table>');

               };
                });

                        $("#tenant-list").jSort({
                              sort_by: 'th.title',
                              item: 'table',
                              order: 'asc'
                            });


                        $(".tenantList").jSort({
                              sort_by: 'td.shopName',
                              item: 'tr',
                              order: 'asc'
                           });

                        $(".categoryList").jSort({
                              sort_by: 'td',
                              item: 'tr',
                              order: 'asc'
                           });
                        $("#instruction").show();
                        $("#ajaxLoading").hide();

              },
              error: function (request, status, error) { 
                        alert(request.status + ", " + status + ", " + error); 
                      }
                      });

shop.json 是一个 1.2mb 的 json 文件,存储在本地,在 jsonlint 处完全验证,错误为 0。所以我想不会有任何跨源问题。但是,当我在 IE 上测试我的脚本时,错误函数执行了,并给了我一个警报:

  200, parseerror, SyntaxError: Invalid Character

IE 开发者控制台中的 ResponseHeader 显示了我的 JSON 文件的全部内容,它似乎是 200 OK。

请帮助我。p/s:上面的代码,我之前加了“ dataType: json”和“ contentType: "application/json; charset=utf-8”,也是同样的错误。

让我知道有人需要这方面的更多信息。

4

1 回答 1

0

可能为时已晚,但请检查您所指的“shop.json”文件。JSON 对象中的任何属性都不应是“未定义”值

如果您尝试解析的 JSON 对象中的属性之一是“未定义”,则 IE 会给出该错误。

于 2014-12-04T06:05:48.930 回答