gpt4 book ai didi

javascript - IE9 的 AJAX 响应包含无效字符

转载 作者:行者123 更新时间:2023-12-01 05:46:44 24 4
gpt4 key购买 nike

我在 IE9 中得到了明显不同的 JSON 响应,并且不确定问题出在哪里:

我的JS(这是使用jquery形式-http://malsup.com/jquery/form/):

var self = this,
options = {
beforeSubmit: this.beforeSubmit,
uploadProgress: this.uploadProgress,
success: this.uploadSuccess,
resetForm: true
},
form = $(this.forms.addNewDocument);

$(form).ajaxSubmit(options);

我正在记录 uploadSuccess 中的响应。

在我的 PHP 中,在使用 json_encode 之前,我得到的响应是:

array(2) {
["values"]=>
array(1) {
["categoryId"]=>
string(1) "1"
}
["template"]=>
array(1) {
["body"]=>
string(211) "<li id="18"><span class="doc-title">test4.txt</span>&nbsp;<span class="doc- date">9/30/2014</span>&nbsp;<span class="doc-user">Ling Chow</span><i class="fa fa-download"></i><i class="fa fa-times-circle"></i></li>"
}
}

然后,当我将数组包装在 json_encode($myresult) 中并记录 ajax 响应时,我得到以下结果:

In IE 9
{"values":{"categoryId":"1"},"template":{"body":"<li id='\"6\"'><span class='\"doc- title\"'>test.txt&lt;\/span&gt;&nbsp;<span class='\"doc-date\"'>9\/30\/2014&lt;\/span&gt;&nbsp;<span class='\"doc-user\"'>Ling Chow&lt;\/span&gt;<i class='\"fa' fa-download\?="">&lt;\/i&gt;<i class='\"fa' fa-times-circle\?="">&lt;\/i&gt;&lt;\/li&gt;"}}</i></i></span></span></span></li>

In IE10/Chrome
{"values":{"categoryId":"1"},"template":{"body":"<li id=\"9\"><span class=\"doc-title\">accredmaster2.html<\/span>&nbsp;<span class=\"doc-date\">9\/30\/2014<\/span>&nbsp;<span class=\"doc-user\">Ling Chow<\/span><i class=\"fa fa-download\"><\/i><i class=\"fa fa-times-circle\"><\/i><\/li>"}}

IE9 添加了很多单引号,其中有一个“?=”,看起来它提前结束了 JSON。为什么会发生这种情况,为什么特定于 IE9?

最佳答案

在 php.ini 中的 json_encode 之前使用 header('content-type: application/json');这会让 IE9 意识到您正在返回 json 并且不会尝试转义所有内容。

关于javascript - IE9 的 AJAX 响应包含无效字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26126491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com