如何在jQuery .load()函数中传递Accept标头,因为它需要传递.
您需要beforeSend在ajax方法中使用该参数,因为load不公开此功能:
$.ajax({
url: "http://www.server.com/",
beforeSend: function(jqXHR, settings) {
jqXHR.setRequestHeader("Accept", "application/json");
},
// You need to manually do the equivalent of "load" here
success: function(result) {
$("selector").html(result);
}
});
Run Code Online (Sandbox Code Playgroud)