问题描述
在客户端使用 loadJSON 我需要将 playerid
和 itemid
发送到服务器,但我只知道如何单独发送它们,我如何在 loadJSON 中同时使用它们,所以我可以像let itemid=req.params.itemid
let playerid=req.params.playerid
获取信息
客户:
itemid = 1;
loadJSON('/AddItem/'+playerid,(dataReceived)=>{
for (let j = 0; j < arrPanels[currPanel].slots.length; j++) {
if (arrPanels[currPanel].slots[j].item == dataReceived[0].itm_id) {
arrPanels[currPanel].slots[j].itemQuantity = dataReceived[j].plitm_quantity
}
}
});
服务器:
app.get('/AddItem/:playerid',(req,res)=>{
let playerid=req.params.playerid;
let itemid=req.params.item;
let sql ="SELECT itm_id FROM playeritems WHERE pl_id='"+playerid+"' AND itm_id='" +itemid+ "'";
db.query(sql,(err,result)=>{
if(err) throw err;
if(result.length<1){
let sql = "INSERT INTO playeritems (pl_id,itm_id,plitm_quantity) VALUES ('"+playerid+"','"+itemid+"','"+add1+"')"
db.query(sql,result)=>{
if(err) throw err;
let sql ="SELECT * FROM playeritems WHERE pl_id='"+playerid+"' AND itm_id='" +itemid+ "' AND plitm_quantity > 0";
db.query(sql,result)=>{
if(err) throw err;
res.send(result);
});
});
}else{
let sql ="UPDATE playeritems SET plitm_quantity = plitm_quantity + 1 WHERE pl_id='" +playerid+ "' AND itm_id='" +itemid+ "'"
db.query(sql,result)=>{
if(err) throw err;
let sql ="SELECT * FROM playeritems WHERE pl_id='"+playerid+"' AND itm_id='" +itemid+ "' AND plitm_quantity > 0";
db.query(sql,result)=>{
if(err) throw err;
res.send(result);
});
});
}
});
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)