gpt4 book ai didi

jquery - 资源被解释为文档,但在 Chrome 开发者工具中传输时带有 MIME 类型 application/json 警告

转载 作者:行者123 更新时间:2023-12-03 21:28:16 25 4
gpt4 key购买 nike

我有以下代码片段,它使用 jQuery Form 插件将表单发布到服务器(在 ajax 中)。

  var options = {
dataType: "json",
success: function(data) {
alert("success");
}
};

$form.ajaxSubmit(options);

形式:

<form enctype="multipart/form-data" id="name_change_form" method="post" action="/my_account/"> 
<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='6c9b552aaba88b8442077e2957e69303' /></div>
<table>
<tr>
<td>
<label for="id_first_name">First name</label>:
</td>
<td>
<input name="first_name" value="Patrick" maxlength="30" type="text" id="id_first_name" size="30" />
</td>
</tr>
<tr>
<td>
<label for="id_last_name">Last name</label>:
</td>
<td>
<input name="last_name" value="Sung" maxlength="30" type="text" id="id_last_name" size="30" />
</td>
</tr>
</table>
<input type="hidden" name="form_id" value="name_change_form" />
</form>

ajax 实现工作正常。但我收到警告

Resource interpreted as Document but transferred with MIME type application/json

在 Chrome 开发者工具中。我想找出为什么会出现警告,或者更好的是解决它的方法。

我改为使用 $.post ,从那时起错误就神奇地消失了。我不知道为什么 $.post 有效,但 $form.ajaxSubmit 无效。如果有人能提供他们的解释那就太好了。至少,这个问题已经解决了。以下是新代码。

var url = $form.attr("action");
$.post(
url,
$form.serialize(),
function(data) {
alert("success");
},
"json"
);

最佳答案

我遇到了同样的错误。对我有用的解决方案是:

From the server end, while returning JSON response, change the content-type: text/html

现在浏览器(Chrome、Firefox 和 IE8)不会给出错误。

关于jquery - 资源被解释为文档,但在 Chrome 开发者工具中传输时带有 MIME 类型 application/json 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6934393/

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