Ajax Request failed to fetch data from API

Hello Campers!
I’m doing the intermediate project “Random Quote Generator” but I;m stuck at the step of dealing with APIs , I have never dealt with them before.
so here is a basic prototype (2 Paragraphs and Button) I don’t know why is it failed when click button to get data from the API…
codepen : https://codepen.io/HamedOKhaled/pen/xjVqYm
Thanks in Advance

I know it’s tough. APIs are a pain. They’re all different, they are often poorly documented, and they can change without warning.

Here is some simpler code to make that API call you’re trying to do:

var url = "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=10&mashape-key=Y2WnFKhquumshQq4C03BYJu2Ap2bp1WYqMRjsnTP20eycCnzdX";

$.getJSON(url, function(json) {
  alert('success!');
  console.log(json);
});

I’ve included the key in your url. Try to understand what is happening here.

I noticed that the url is missing from the example you had.

First, Thanks for replying ! :slight_smile:
Second it’s working !!
Third , what is the key that u included in the url??
Forth, How could u construct the url in this way ??
Thanks :slight_smile:

  1. np, that’s why we’re here
  2. cool
  3. If you mean:
...&mashape-key=Y2WnFKhquumshQq4C03BYJu2Ap2bp1WYqMRjsnTP20eycCnzdX”

I got that from your code. I assumed that it is your key. If it is not (you cut and paste it from someone else) then you should register and get your own key.
4. I just used that string before. How did I get it? I probably saw it somewhere. It’s basically doing what you did in your original but passing the key as a query string instead of a header. I doubt that is universally acceptable, but it works here. APIs sometimes require some trial and error.