微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 loadJson 中发送多个值?

如何解决如何在 loadJson 中发送多个值?

在客户端使用 loadJSON 我需要将 playeriditemid 发送到服务器,但我只知道如何单独发送它们,我如何在 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 举报,一经查实,本站将立刻删除。