jquery – 资源解释为Document但在Chrome Developer Tools中使用MIME类型application / json警告进行传输

我有以下代码片段,它使用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)不会出错.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...