hey guys, I’ve been 2 days with this challenge but I’m stuck, it shows me this error:
Uncaught TypeError: $.ajax is not a function
I don’t know what else I should do, this my code:
It looks like you have jQuery added, otherwise it would have thrown an error at the first instance of “$”. Is that the only error that comes up? I do notice a syntax error though in the console log. You’ve added a period when it looks like you meant to have added a colon. Also it needs to be inside of the string.
It looks like .ajax is not included in the slim version of jQuery. Try again with the full version: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js.
Then you’ll see this warning in the console:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
You’ll probably have to use a proxy to deal with this, or use a different API (this works btw: https://cors-anywhere.herokuapp.com/https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en)
If I understood it correctly, it’s because the JSON response is coming from a different domain (which is not allowed by default). If the response has Access-Control-Allow-Origin set to * in its header, you can use the URL as it is.
Someone wrote a detailed explanation in the forum long ago: