weixin_33734785 2015-11-03 14:23 采纳率: 0%
浏览 3

$ .ajax()到$ .getJSON()

I would like to ask if there is a method to parse data from $.ajax() to $.getJSON() please?

This is the $.ajax() example:

var apiUrl = 'https://api.com/url_here';
var apiKey = 1234567890;
var apiSecret = 0987654321;

var data = {};

$.ajax({
  url: apiUrl,
  headers: {
    "Authorization": "Basic " + btoa(apiKey+ ":" + apiSecret)
  },
  data: data,
  dataType: 'json',
  type: 'GET',

  success: function(data) {
    console.log(data);
  },

  error: function(data) {
    console.log(data);
  }
});

And this is what I have in my $.getJSON(), where I have a struggle in calling the headers for authentication:

    $.getJSON(apiUrl, function(json){

        console.log(JSON.stringify(json));

    });

Thanks a lot! xxx

  • 写回答

0条回答 默认 最新

    报告相同问题?