Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass Accept header in jQuery .load() function

Tags:

jquery

ajax

image

How to pass Accept header in jQuery .load() function as It need to be passed.

like image 531
ducktyped Avatar asked Jan 18 '23 16:01

ducktyped


1 Answers

You need to utilize the beforeSend parameter in the ajax method, since load does not expose this functionality:

$.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);
    }
});
like image 92
Jon Avatar answered Jan 31 '23 00:01

Jon