Goodreads Developers discussion

29 views
Callback MIME type confusion.

Comments Showing 1-4 of 4 (4 new)    post a comment »
dateUp arrow    newest »

message 1: by Sam (new)

Sam | 2 comments Hi Goodreaders.

I've used the xml flavor of the goodreads API in php casually for a number of years now, but I was trying out some JS-based stuff as listed in the docs and... I can't figure out the specific way in which I'm being stupid.
So... I need your help in telling me just how stupid I am. Because clearly I am doing something stupid.

I'm trying to access review_counts via the callback method.

- The request returns the result I want, formatted as a function.
- The code is putting the script tag in the header correctly.
- The browser throws an error saying "Refused to execute script from [Goodreads] because its MIME type ('js') is not executable, and strict MIME type checking is enabled."
- Indeed, Goodreads does appear to be delivering the file with that MIME type.
- I have tried setting the attributes on the head tag via setAttribute() to no avail.

You can C&P the following into codepen or whatever and experience the same thing I am:

function myCallback(result) {
console.log(result);
}

var scriptTag = document.createElement('script');
scriptTag.src = "https://www.goodreads.com/book/review...

document.getElementsByTagName('head')[0].appendChild(scriptTag);

... yep.

If anyone could point me to the way, the truth, and the light, that would be swell.

Thank you!
- S


message 2: by Ioan (new)

Ioan Mosincat | 5 comments Hey there,

I added scriptTag.type = "type='application/json'" in there and I don't get the error anymore.

The result you are getting from the API is a json, not a js file; that's why you need to explicitly set the type of the response.


message 3: by Sam (new)

Sam | 2 comments Thanks for your help on this, Ioan!

I was super excited because the error went away!

But... then I realized I was no longer getting an error because it was no longer actually _loading_ the remote file. That is to say, no network request was made for the file.

For reasons I do not understand, the file does not load when setting the type.

Using the setAttribute() method leads to an identical-_looking_ code, but one in which the jsonp is retrieved... but then blocked because of the mime type error.

Did you have it working in a fiddle or something?

Thanks!
Sam


message 4: by Ioan (new)

Ioan Mosincat | 5 comments Nope, unfortunately, I didn't manage to get it working either.


back to top