1

Really inexperienced and need a pure javascript api request. Any idea how to convert this cURL request to jquery ajax?

curl --get --include 'https://igdbcom-internet-game-database-v1.p.mashape.com/characters/?fields=*&limit=10' \
  -H 'X-Mashape-Key: DFGqKmjjWB********************4WVDjsnvStEw2yMsBIo' \
  -H 'Accept: application/json'

Thanks in advance!

1
  • Please show what you've tried so far. Commented Oct 23, 2016 at 6:14

2 Answers 2

1

Using jQuery:

$.ajax("https://igdbcom-internet-game-database-v1.p.mashape.com/characters/?fields=*&limit=10", {
    method: "GET",
    headers: {
      "X-Mashape-Key": "DFGqKmjjWB********************4WVDjsnvStEw2yMsBIo",
      "Accept": "application/json"
    },
    dataType: "json",
    success: (data) => {
      console.log(data) // your data
    },
    error: (xhr, textStatus, errorThrown) => {
        console.log(textStatus, errorThrown);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

Update:

The --include flag in curl displays response headers. Updated to get them using jQuery.


Use:

$.ajax({
    url: "https://igdbcom-internet-game-database-v1.p.mashape.com/characters/?fields=*&limit=10",
    headers: { 
      'X-Mashape-Key': 'DFGqKmjjWB********************4WVDjsnvStEw2yMsBIo',
      'Accept': 'application/json' 
    },
    type: "GET",
    success: function(data, textStatus, request){
      alert(request.getResponseHeader('some_header')); // Get a specific response header
    },
    error: function (request, textStatus, errorThrown) {
      alert(request.getResponseHeader('some_header')); // Get a specific response header
    }
  });

To get all the response headers, use getAllResponseHeaders()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.