[英]What's diffrence in jQuery ajax dataType="json" vs JSON.parse()
Is there any real diffrence between using dataType='json' and parse response by JSON.parse(response) in jQuery Ajax?在 jQuery Ajax 中使用 dataType='json' 和通过 JSON.parse(response) 解析响应之间是否有任何真正的区别?
$.ajax({
url: path,
type: 'POST',
dataType: 'json',
data: {
block : lang,
},
}).done(function(response, textStatus, jqXHR)
{
output = response;
});
VS VS
$.ajax({
url: path,
type: 'POST',
data: {
block : lang,
},
}).done(function(response, textStatus, jqXHR)
{
output = JSON.parse(response);
});
dataType: 'json'
: dataType: 'json'
:
Accept
request header to tell the server that JSON is the desired response formatAccept
请求 header 告诉服务器 JSON 是所需的响应格式Content-Type
response header says the format is.Content-Type
响应 header 所说的格式是什么。 (jQuery's default behaviour is to use the Content-Type
to determine the correct parser). Content-Type
来确定正确的解析器)。 JSON.parse
: JSON.parse
:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.