我的主题片段中包含以下代码。它由我的商店中的测试页调用,而不是应用程序。据我所知,我不需要采取任何认证步骤。该代码返回403错误。我无法弄清楚为什么。通过POST(ajax)发送JSON数据;从Shopify获取403
$(document).ready(function() {
$("#process-all-products").click(function(e) {
e.preventDefault();
var resultDiv = $("#resultDivContainer");
var collection_id;
var toAdd = new Array();
for(i=0; i < length; i++){
toAdd.push({
variant_id: $("#variant-"+i).val(),
quantity_id: $("#quantity-"+i).val() || 0
});
}
function createCollection(){
var params = {
type: 'POST',
url: '/admin/custom_collections.json',
data: { "custom_collection": { "title": "my_collection_title" } },
dataType: 'json',
success: function (response) {
switch (response) {
case true:
collection_id = response.id;
console.log("collection_id [" + collection_id + "]");
break;
default:
resultDiv.html(response);
}
},
error: function (xhr, ajaxOptions, thrownError) {
console.log("create collection failed!");
alert(xhr.status);
alert(thrownError);
}
};
$.ajax(params);
};
createCollection();
});
});
</script>
403错误表示您无权执行请求。我的请求中没有看到任何验证参数。 – Kolban 2014-11-24 02:19:12