【问题标题】:$.ajax 200 OK, parseerror, invalid character on Internet Explorer 7,8,9,10$.ajax 200 OK,解析错误,Internet Explorer 7、8、9、10 上的无效字符
【发布时间】:2013-12-27 11:20:42
【问题描述】:

这段代码可以在 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”,也是同样的错误。

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

【问题讨论】:

  • this answer 有帮助吗?
  • 不幸的是,我在本地和服务器上使用 IE 测试了这段代码,显示了相同的结果。 Chrome/FF 都运行良好!我仍然想知道它有什么问题。 :(
  • 你有想过这个吗?

标签: javascript json internet-explorer parse-error invalid-characters


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2013-06-10
    • 1970-01-01
    • 2015-02-07
    • 2011-05-01
    • 2015-05-21
    • 2011-07-15
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    相关资源
    最近更新 更多