Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNicholas D'Amico
Front End Web Development Techdegree Graduate 25,692 PointsTeam Treehouse API JSONP Help
I'm trying to make a JSONP request to my profile at https://teamtreehouse.com/nicholasdamico.json. It doesn't seem to be working. I'm not sure if the callback is the problem since nothing is logged to the console, or if the request is setup properly. Any advice or help would be greatly appreciated. Also i'm not using jQuery.
Thanks, Nick
here is the markup in the index.html file
<script src="assets/scripts/app.js"></script>
<script type="application/json" src="https://teamtreehouse.com/nicholasdamico.json?callback=treehouse"></script>
And here is the function in my app.js file
function treehouse(data) {
console.log(data.points.total);
}
Also, I added the type="application/json" to the script tag with the request because of an error I was receiving to the console. This is the error message, "because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled."
2 Answers
Seth Kroger
56,413 PointsUnless the API docs say it can return a JSONP response it probably doesn't. You're just getting a straight JSON response and should request/handle it appropriately.
Mikkel Rasmussen
31,772 PointsI think you should look at this:
http://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery
Nicholas D'Amico
Front End Web Development Techdegree Graduate 25,692 PointsNicholas D'Amico
Front End Web Development Techdegree Graduate 25,692 PointsThanks Mikkel and Seth, I appreciate the responses! I was confused about making XMLHttpRequests to other domains. I'm making a request for HTML within my own domain for this project, but for some reason I thought when requesting from Treehouse I would have to use a method like JSONP. As soon as I tried making a XHR request it returned a JSON string from my profile page and all I had to do is parse it.
Thanks for helping. Nick