Hey guys, so I’m struggling with pulling data from the Forismatic API (http://forismatic.com/en/api/) for this project.
From the API documentation I know the data is formatted with tags like “quoteText” & “quoteAuthor” which is the data I require, however I can’t figure out how to pull this from the API.
In the link below you will see I’ve attempted to iterate through the JSON object and append the required info to the required div but so far I’m not having any joy.
It’s my first time using jQuery for a project so it’s very possible that I’ve made some glaring errors! Help would be greatly appreciated.
I got the following response in JSON : {“quoteText”:“It is not enough to have a good mind; the main thing is to use it well. “, “quoteAuthor”:“Rene Descartes “, “senderName”:””, “senderLink”:””, “quoteLink”:“http://forismatic.com/en/7d0c3ec445/”}
In order to access the quote text and author I would try this success:function(json){
//doSomethingWithIt//json.quoteText
//doSomethingWithIt//json.quoteAuthor
}
P.S. - It’s always helpful to just paste your api call into your browser to see what response you get to verify correct syntax.
Do you know of a way I can view the JSON data I’m pulling without using the chrome console? Unfortunately my current set up is an android tablet so I’m unable to use the console!
EDIT: Apologies I’ve only just seen your comment about pasting the API call into the browser to check the result, I had no idea this was possible thanks!
You will not be able to change the inner HTML of an element of create a new HTML element and change its inner value using JSON due to Cross-Origin Resource Sharing (CORS) as your browser will block a cross-origin request. You will need to use the JSONP format to do what you are trying to achieve.
This is because browser security does not allow data exchange if the data is of different origin than you origin of your website.
otherwise, i was getting a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” error. this is something to with cross domain blocking by browser