$ .ajax-数据类型 [英] $.ajax - dataType
本文介绍了$ .ajax-数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
contentType: "application/json; charset=utf-8",
dataType: "json",
vs.
contentType: "application/json",
dataType: "text",
推荐答案
-
contentType
是发送到服务器的标头,指定特定格式.- 示例:我正在发送json或XML
contentType
is the header sent to the server, specifying a particular format.- Example: I'm sending json or XML
- 期望JSON,XML或HTML等...jQuery尝试将其弄清楚的默认值.
$.ajax()
文档对此也有完整描述.The
$.ajax()
documentation has full descriptions of these as well.在您的特定情况下,第一个请求将响应保存在
utf-8
中,第二个则不在乎.同样,第一个将响应视为javascript对象,第二个将其视为字符串.In your particular case, the first is asking for the response to be in
utf-8
, the second doesn't care. Also the first is treating the response as a javascript object, the second is going to treat it as a string.第一个是:
success: function(data) { //get data, e.g. data.title; }
第二个:
success: function(data) { alert("Here's lots of data, just a string: " + data); }
这篇关于$ .ajax-数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文