【发布时间】:2015-12-22 20:09:03
【问题描述】:
我正在使用 ionic 构建餐厅应用程序,我需要从 shopify api 访问数据。如何从 shopify api 访问数据?
$http({
method: 'GET',
url: 'https://xxxxxxxxxxxxxxxxx:xxxxxxxx@xxxxxx.myshopify.com/admin/customers.json',
header: {'Access-Control-Allow-Origin': "*"}
}).then(function(resp) {
alert(JSON.stringify(resp));
}, function(err) {
alert("err"+JSON.stringify(err));
// err.status will contain the status code
})
在一些论坛中,我得到了上面的 http 请求代码。但是上面的代码返回错误状态:0。请帮忙。
【问题讨论】:
-
听起来好像在 myshopify.com 域上没有启用 CORS。您对
Access-Control-Allow-Origin标头的使用没有实际意义,因为它必须由服务器而不是客户端设置为允许访问。 -
除了@RoryMcCrossan 所说的之外,您可能还需要在请求中传递某种
Authorization标头。我不熟悉 shopify API 要求,但这是一种常见做法。 -
@SteamDev 我相信这就是 OP 在 URL 的子域部分中用
x字符阻止的内容。 -
@RoryMcCrossan 上面的 url,如果输入到浏览器中,它会返回一个 json 数据.. 但我无法通过 ionic 访问它..
-
听起来你可能被Same Origin Policy屏蔽了。如果是这种情况,您将需要在服务器端进行请求。
标签: jquery cordova ionic-framework ionic shopify