Javascript 收听Ajax调用并添加自定义参数
我想听听所有Shopify add.js调用,然后根据需要添加自定义POST参数 我能够监听这些调用,但不确定是否可以使用window.fetch添加参数 下面是代码示例-Javascript 收听Ajax调用并添加自定义参数,javascript,ajax,dom-events,shopify,Javascript,Ajax,Dom Events,Shopify,我想听听所有Shopify add.js调用,然后根据需要添加自定义POST参数 我能够监听这些调用,但不确定是否可以使用window.fetch添加参数 下面是代码示例- (function(ns, fetch) { if (typeof fetch !== 'function') return; ns.fetch = function() { const response = fetch.apply(this, arguments); response.then(res
(function(ns, fetch) {
if (typeof fetch !== 'function') return;
ns.fetch = function() {
const response = fetch.apply(this, arguments);
response.then(res => {
if ([
`${window.location.origin}/cart/add.js`,
`${window.location.origin}/cart/update.js`,
`${window.location.origin}/cart/change.js`,
`${window.location.origin}/cart/clear.js`,
].includes(res.url)) {
res.clone().json().then(data => console.log(data));
}
});
return response;
}
}(window, window.fetch))