json - 差异 : JSONP vs GET

标签 json wordpress http get jsonp

这是我的问题,这些请求之间有什么区别?

我在尝试执行 get 请求时遇到问题,出现错误

XMLHttpRequest cannot load http://urbanetradio.com/wp-json/posts. The 'Access-Control-Allow-Origin' header has a value 'http://localhost:8100' that is not equal to the supplied origin. Origin 'http://run.plnkr.co' is therefore not allowed access.

get 请求指向 my-site-url/wp-json/posts,这是一个 WordPress 帐户。和 this is the method I am using

所以,有人说,使用 jsonp 而不是 get,但为什么呢?

最佳答案

Jsonp 用于支持跨源资源共享的 Web API。下面这篇文章举例说明了如何发起支持cors的请求。如果 webapi 未配置为允许来自您的主机的请求,您可能无法在不更改 api 的情况下使其工作。

支持cors的网络请求: http://www.html5rocks.com/en/tutorials/cors/

设置一个使用 cors 的 web api: http://mobile.codeguru.com/csharp/.net/net_asp/using-cross-origin-resource-sharing-cors-in-asp.net-web-api.html

关于json - 差异 : JSONP vs GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30197436/

相关文章:

java - 将 Java 类(用于代码表示)解析为 JSON 对象

php - WordPress 如何仅向订阅者授予对页面的访问权限

php - 在 WooCommerce 管理订单列表中添加自定义操作按钮

python - 在 Python 请求数据中包含列表

facebook - 从应用程序访问 "Public"Graph API 资源?

javascript - 从 json 响应中解析动态 json 对象

json - Spark 2.1.1 : Parsed JSON values do not match with class constructor

php - PHP 数组中的 JSON 键值对使用 json_encode() 函数

javascript - 使用输入隐藏和显示特定类名称的 div,并且仅显示该类

http - 如何避免http响应中的点文件或点目录