$.post设置请求头接收html
导读:$.post设置请求头接收html在使用$.post发送数据请求时,我们可以设置请求头来接收html格式的数据,具体方法如下:$.post(url, data, function(response {console.log(respons...
$.post设置请求头接收html
在使用$.post发送数据请求时,我们可以设置请求头来接收html格式的数据,具体方法如下:
$.post(url, data, function(response) { console.log(response); } , 'html');
其中,'html'参数表示要接收的数据格式为html。如果不设置或设置为其他格式,那么响应体中的数据将以文本格式返回。
另外,我们也可以通过设置请求头来接收json格式的数据,具体方法如下:
$.ajax({ url: url,type: 'POST',data: data,dataType: 'json',success: function(response) { console.log(response); } ,error: function(jqXHR, textStatus, errorThrown) { console.log(textStatus, errorThrown); } } );
其中,dataType参数设置为'json'表示要接收的数据格式为json。如果不设置或设置为其他格式,那么响应体中的数据将会以文本格式返回。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: $.post设置请求头接收html
本文地址: https://pptw.com/jishu/298996.html