Add header in JQuery getJson function

0

Is it possible to add some header in jQuery's $ .getJson function?

I'm having cross-origin issues and have read in some places that adding some header information can solve this problem.

    
asked by anonymous 17.01.2017 / 13:37

1 answer

2

$ .getJSON is a simplified one of:

$.ajax({
    dataType: "json",
    url: url,
    data: data,
    success: success
});

So, to set a header, a call like:

$.ajax({
    dataType: "json",
    beforeSend: function(request) {
        request.setRequestHeader("Authority", authorizationToken);
    },
    url: url,
    data: data,
    success: success
});

However, if the problem is CORS, the solution will only be if the endpoint (server) allows the CORS. See this answer to understand what it is and this which contains an example of how to allow. But if you do not have the autonomy to change some configuration on the server, nothing can be done on the front end.

    
17.01.2017 / 13:57