Shopify API跨域Ajax请求 [英] Shopify API Cross Domain Ajax Request

查看:404
本文介绍了Shopify API跨域Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从shopify获取客户详细信息.我已经从shopify管理员将域重定向到另一个域.

I am using the below code to get the customer details from shopify. I have redirected my domain to the other domain from the shopify admin.

function setEmailWithLoggedInUser(callback) {
$.ajax({
      url: 'https://new-website-shopify.myshopify.com/admin/customers/'+__st.cid+'.json',
      crossDomain: true,
      beforeSend: function(xhr) {
           xhr.setRequestHeader("Authorization", "Basic XXXXXXXXXXXX")
      }, success: function(data){

          console.log(data);

          if(callback)
            callback();      
         }
})  

我已经做了很多工作,但是找不到解决方案. 我收到此错误:

I have done a lot of work around but unable to find the solution. I am getting this error:

无法加载资源:服务器响应状态为404 (未找到)

Failed to load resource: the server responded with a status of 404 (Not Found)

XMLHttpRequest无法加载 https://new-website-shopify.myshopify.com/admin/customer/7094124372.json . 对预检请求的响应未通过访问控制检查:

XMLHttpRequest cannot load https://new-website-shopify.myshopify.com/admin/customers/7094124372.json. Response to preflight request doesn't pass access control check:

请求的请求上没有'Access-Control-Allow-Origin'标头 资源.因此,来源' https://www.beirutshopping.com '不是 允许访问.响应的HTTP状态代码为404.

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.beirutshopping.com' is therefore not allowed access. The response had HTTP status code 404.

推荐答案

我将为您省去一些麻烦.您不能从商店的前端致电/admin,因为这会将您的访问令牌公开.相反,如果您想从前端访问API,请使用App Proxy模式,从而可以安全地进行Ajax调用以实现您的目标.

I will save you some headaches with this answer. You cannot call /admin from the front-end of a store, as that exposes your access token to the public. Instead, if you want to access the API from the front-end, use the App Proxy pattern, allowing you to securely make Ajax calls to accomplish your goals.

实际上,您几乎肯定会失败,而一旦成功存在,成功的一切都会使您的商店迅速遭受恐怖袭击.就像被悲伤的熊猫所取代,或者被其他人讨厌一样.

As it is, you are almost certain to fail, and any success you hack into existence will quickly expose your shop to horrors. Like being replaced with sad pandas, or otherwise being reckd.

这篇关于Shopify API跨域Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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