Skip to content

Conditionally render JSONP #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joeyespo
Copy link
Contributor

Here's my attempt to fix #3.

Pros

  • This allows you to use a JSON endpoint normally
  • This complies with the expected JSONP behavior that wraps your JSON when a callback parameter is provided (and defaults to 'callback' when no value is specified) or application/javascript is used
  • No custom code needed in your view function

Cons

  • The media_type is now set to application/json from JSONRenderer (and therefore, if callback is provided without explicitly requesting the proper application/javascript content type, it will respond with application/json)

There's another solution from the docs that demonstrates how to use multiple renderers (based on accepted media type). That method would allow you to use application/javascript again to eliminate the above con, but if you're manually doing that, you may as well manually wrap your json too without this plugin. Because you want to cut down on verbosity, the pros may outweigh the con.

Also, Chrome didn't complain when I tried <script src="myendpoint?callback=mycallback">. And jQuery uses the right media type when using JSONP, so no issue there.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Requirements for JSONP are too restrictive
1 participant