122

I have a webservice that when called without specifying a callback will return a JSON string using application/json as the content type.

When a callback is specified it will wrap the JSON string in a callback function, so it's not really valid JSON anymore. My question is, should I serve it as application/javascript in this case or still use application/json?

2 Answers 2

147

Use application/javascript. In that way, clients can rely on the content-type without having to manually check whether a response has padding or not.

3
  • 1
    It fails in IE 9 with message "SEC7112: Script from xyz.com was blocked due to mime type mismatch " Any idea why ?
    – Pit Digger
    Commented Sep 12, 2011 at 20:05
  • Content type "application/javascript" may mismatch with "text/javascript" that specified in script tag (or expected by default for some reason) Commented Mar 26, 2013 at 21:18
  • Based on the information in this article text/javascript and application/javascript would work in IE 9. I wonder @pit-digger if the server just wasn't returning the correct content-type header.
    – spig
    Commented May 6, 2014 at 14:13
122

Use application/json as per rfc4627.txt if what you return is plain JSON.

If you return JavaScript (which is really what JSONP is), then use application/javascript as per rfc4329.txt

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.