为JSONP提供服务的最佳内容类型? [英] Best content type to serve JSONP?

查看:116
本文介绍了为JSONP提供服务的最佳内容类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个web服务,在没有指定回调的情况下调用时,将使用 application / json 作为内容类型返回一个JSON字符串。

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

当指定回调时,它会将JSON字符串包装在回调函数中,因此它不再是真正有效的JSON。我的问题是,在这种情况下我应该将其作为 application / javascript 提供还是仍然使用 application / json

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?

推荐答案

使用application / javascript。通过这种方式,客户端可以依赖内容类型,而无需手动检查响应是否有填充。

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.

这篇关于为JSONP提供服务的最佳内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆