资源被解释为文档,但在Chrome开发者工具中使用MIME类型application/json警告进行传输 [英] Resource interpreted as Document but transferred with MIME type application/json warning in Chrome Developer Tools
问题描述
我有以下代码段,该代码段使用jQuery Form插件将表单发布到服务器(使用Ajax).
I have the following snippet, which uses the jQuery Form plugin to post a form to the server (in 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实现工作正常.但我收到警告
The ajax implementation is working fine. But I am getting a warning
资源被解释为文档,但以MIME类型application/json传输
Resource interpreted as Document but transferred with MIME type application/json
在Chrome开发者工具中
.我想找出警告的原因,甚至更好的解决方法.
in Chrome Developer Tools. I want to find out why the warning, or even better, a way to resolve it.
我改用了$.post
,从那以后神奇的是错误消失了.我不知道为什么$.post
可以工作,但是为什么$form.ajaxSubmit
不能.如果有人可以提供他们的解释,那就太好了.至少,此问题已得到解决.下面是新代码.
I changed to use $.post
instead and magically the error was gone since then. I have no idea why $.post
works but not $form.ajaxSubmit
. If someone can offer their explanation that would be great. At the very least, this problem is resolved. Below is the new code.
var url = $form.attr("action");
$.post(
url,
$form.serialize(),
function(data) {
alert("success");
},
"json"
);
推荐答案
我采用了另一种方法.我改用$ .post,此后错误消失了.
I took a different approach. I switched to use $.post and the error has gone since then.
这篇关于资源被解释为文档,但在Chrome开发者工具中使用MIME类型application/json警告进行传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!