1

我正在使用 JSON.parse 将 JSON 字符串转换为 JSON 对象。它适用于 Google Chrome、Firefox、Opera 和 Safari,但不适用于 IE9。每次我使用 JSON.parse Internet Explorer 都会引发“SCRIPT1014:无效字符”错误。我已将 json2.js 包含在脚本中,因为 IE8 不支持 JSON.parse,但它仍然有效,但无济于事。我怎样才能使这项工作?

function run() {
        $("#testing").ajaxSubmit({
            success: function (data) {
                console.log(data);
                var parsedjson = JSON.parse(data);
                var truejson = parsedjson[0];
            }
        });
    }

LOG: <pre>[{"group":null,"name":"lion.jpg","type":"image/png","size":5269,"progress":"1.0","url":"/Upload/UploadHandler.ashx?f=lion.jpg","thumbnail_url":"data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBhQSERQUExMWFRQWFxcZGRgYGBgaGxwiGxodGhwaHBoYHCYfHRojGhgYHy8iIycpLCwsGiAxNTAqNSYsLCkBCQoKDgwOGg8PGiwkHyQsLCwvLCksLCksLCwsKSwsLCwsLCwsLCksLCwsLCwsLCwsKSwsLCwsLCwsLCwsLCksLP/AABEIAIAAsAMBIgACEQEDEQH/xAAbAAADAQEBAQEAAAAAAAAAAAAEBQYDAgcAAf/EADoQAAECBAQDBwIFAwQDAQAAAAECEQADITEEEkFRBWFxEyIygZGh8AaxQsHR4fEUUnIjJGKSM4KiB//EABkBAAMBAQEAAAAAAAAAAAAAAAECAwAEBv/EACARAAICAgIDAQEAAAAAAAAAAAABAhEhMQMSIkFRYRP/2gAMAwEAAhEDEQA/ACZp7iNiYxGABWV2ozQWlDkA2SI1AjzkUhkcoUCovt6x0hLg6c4/FSqEgWFI7C2FKlrCKxdhRh2JfyB1Ni0dKTsHFDByZamSrKwIIdSkpfmHLkQPijOQCRKBTvmp5kO3nCyTSwN0l8AsdhFKKQK6wwwPDOzSsu+f25QIvGzAM+VFq39iI4TxYmgI3sT8MIo07D/KYwmquBGa8WnDI7QgqUSQhCaFRAc10SBcx9KCblR6UHrC7jM1aly+zsUkpbqx+wL8o6Iq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2kheUkoWGoD4tRyLF4b4FFQGYvQPr/wBSx5RhxTBdqrMVEULnZjQUsL15xdaJllw7Ch0KPhQTlS/iPiA9VH0jrFYjMV5O9o76k+w/Q711xP8AppF3rbUkBh7NSBexZCQL1c1Y3qTzJiTxgmmkjlCGUVNQ7UIYORtt6xkpBOZS2YkhKWuXN0ksQGGznzjGRMdR7RXcWpIS1CWqQDzYDyMacOkqV35hdRcBrACmUDZobZpSs3wvDyVFS1FRNA+7t6lz6wYB3jfMQrTQUHsY+TPAqNCOfP7D3juQh0s5LsK+cZYwjJ4O5eGTVRtb9A7dPSEkudlmFdAlyBzUosS+9Egc2h5PFMo5fGhRxGSkKlhVkqQpjYkVApzLwJ+gdimIAQl3okaa1BHrAuNxORAoSFPfQivlGmKxJC/Ef9QAkNRxcjbukehgSctqEkuSXUzCKjdhTPmkhxdz0q1TuH+bhTcSkuK5k1FGynLmPrRwTTrG3EZx7JIQQCVnvAUHh5OD3vEz0o0YcQAKFIyuyWd9VtztlNdKQPwWxlwJf+ySqhEyYopD6Cj3sVA7wMVXQoMS4cCz0vDbFy0ISJaQyUICAEj+23KtS8C9ooEHK7pHiorqTvE5q2XWj6XhlIRVQAAer3FQK2H7RhIWXKiAVEknWtBqBVi0dcYmJlSn/EVNetufx4+4XNBQGb7avDqJNythK8KSXJJFO6AwGvwxrhJ3eKdAPej/AJR+zV9z38h+UL5GHUlRJPcIpWtfsBGqjdxhMGZFO6MzeQLfPOBMdwsKUGDBNX+8FKmgSh3vwku4qd36uIJd0ps+oGtnblSFcTf0E83CnNqNA1Wb5WBcXIIQQARRyXyg8qacobY9WQJDsonX7UhNNmJrmWVCxAqL2feGDeD/2Q==","delete_url":"/Upload/UploadHandler.ashx?f=lion.jpg","delete_type":"DELETE","error":null}]</pre> 
4

3 回答 3

2

答案是删除围绕返回的 json 字符串的“pre”标签,因为 Internet Explorer 会抛出这些标签以保留文本的结构。表单插件确实适用于 Internet Explorer,但仅适用于相同域的情况。不幸的是,IE9 不支持 CORS。通过这样做解决了这个问题......

function imageUploader() {
        $("#testing").ajaxSubmit({
            success: function (data) {
                if (jQuery.browser.msie == true) {
                    var newdata = data.replace('<pre>', '');
                    var newdata2 = newdata.replace('</pre>', '');
                    var parsedjson = JSON.parse(newdata2);
                    var truejson = parsedjson[0];
                    var image = "<img src=" + truejson.thumbnail_url + " alt=" + truejson.name + "/>";
                    $("div#previewIe").html(image);
                } else {
                    var parsedjson = JSON.parse(data);
                    var truejson = parsedjson[0];
                    var image = "<img src=" + truejson.thumbnail_url + " alt=" + truejson.name + "/>";
                    $("div#previewIe").html(image);
                }
            }
        });
    }
于 2012-12-17T16:56:25.367 回答
0

您正在使用 jQuery 表单插件。正如 Kyle 所说,json2.js 在这里是无关紧要的。

IE9不支持通过 ajax 提交文件

因此,jQuery Form Plugin 将表单提交到隐藏的 iframe 作为一种解决方法,这有其局限性。这些限制就是您遇到的问题。

如果响应类型是 HTML 或 XML,这很好,但如果响应类型是脚本或 JSON,则效果不佳,这两种类型通常都包含在 HTML 标记中找到时需要使用实体引用来表示的字符。

于 2012-12-14T22:23:07.250 回答
0

jQuery.browser该属性在 jQuery 1.9 中被删除,只能通过 jQuery.migrate 插件使用。请尝试改用特征检测。

见:http ://api.jquery.com/jquery.browser/

于 2015-03-20T01:58:19.920 回答