问题描述
我正在开发一个带有节点和反应的应用程序。在这个应用程序中,我使用 fetch 函数创建了一个 scriptTag,以便在按下特定按钮时获取客户 ID 和产品 ID。现在,当我获取该数据时,我想将其存储在我的 firebase 数据库中,我无法将其导入我的脚本标记文件中,因为它位于前端。因此,我需要将数据从我的前端发送到应用程序的后端,但我很困惑,如果我使用 fetch 函数发出 POST 和 GET 请求,我应该使用什么 URL?而且,fetch 函数是否可以发布变量值?
Scripttag.js
const header = $('header.site-header').parent();
header.prepend('<div>Hello this is coming from the public folder </div>').css({'background-color':'orange','text-align': 'center'})
function addWishList(customer,productid){
/*
fetch(`url`,{
method: 'POST',headers: {
'Content-Type':,"X-Shopify-Access-Token":,},body:
}})
})
*/
console.log('adding item to the wishlist!!')
}
function removeWishList(){
console.log('removing item from the wishlist!!')
}
var wishbtn = document.querySelector('.wishlist-btn')
wishbtn.addEventListener('click',function(){
if(this.classList.contains('active')){ //condition to check if the button is already pressed
removeWishList();
this.classList.remove('active');
this.innerHTML = 'Add to wishlist'
}
else{
var customer = wishbtn.dataset.customer;
if(customer == null || customer == ''){
console.log('Please log in to add this item to your wishlist')
}
else{
var productid = wishbtn.dataset.product;
this.classList.add('active'); //when the user presses add to wishlist button,it add active to the button's class
this.innerHTML = 'Remove from wishlist'
addWishList(customer,productid);
}
}
})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)