How can I pass request headers with jQuery's getJSON() method?

前端 未结 3 706
迷失自我
迷失自我 2020-12-04 17:07

I need to do a getJSON() request, but how do I pass authorisation and custom headers?

I am getting issues that the request header is taking the name, bu

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 17:53

    The $.getJSON() method is shorthand that does not let you specify advanced options like that. To do that, you need to use the full $.ajax() method.

    Notice in the documentation at http://api.jquery.com/jQuery.getJSON/:

    This is a shorthand Ajax function, which is equivalent to:

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

    So just use $.ajax() and provide all the extra parameters you need.

提交回复
热议问题