如何在jQuery .load()函数中传递Accept标头

duc*_*ped 4 ajax jquery image

如何在jQuery .load()函数中传递Accept标头,因为它需要传递.

Jon*_*Jon 7

您需要beforeSendajax方法中使用该参数,因为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)