<分区>
我已经编写了一个 JS 函数来将 categoryId 和 shopId 以及 page:0 发布到一个 api,这是我的函数:-
getInsideMenu(categoryid,shopid){
var formBody = [];
var details={
'categoryId':categoryid,
'shopId':shopid ,
'page':'0'
};
for (var property in details) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
return fetch(
`${serverAddress}/api/shopProducts`,
{
method: 'POST',
body: formBody,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
).then((res)=>(res.json()))
},
但是我得到的是 null 。我想这个函数没有正确定义。可以做些什么来修复它。它在 POSTMAN 中运行良好。 [![这是我在 postman 中发送的方式][1]][1]