程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了MERN 堆栈,axios 将当前状态发布到 DB 错误 400 错误请求大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决MERN 堆栈,axios 将当前状态发布到 DB 错误 400 错误请求?

开发过程中遇到MERN 堆栈,axios 将当前状态发布到 DB 错误 400 错误请求的问题如何解决?下面主要结合日常开发的经验,给出你关于MERN 堆栈,axios 将当前状态发布到 DB 错误 400 错误请求的解决方法建议,希望对你解决MERN 堆栈,axios 将当前状态发布到 DB 错误 400 错误请求有所启发或帮助;

按钮点击监听事件: 更新状态,向 mongoDB 发送 axios post 请求 错误堆栈: xhr.Js:177 POST http://localhost:3000/auction-items/609204cd33b39d50c8181368/edit 400(错误请求) dispatchXhrrequest @ xhr.Js:177 xhrAdapter @ xhr.Js:13

Timer.Js:189 Error: request Failed with status code 400
at createError (createError.Js:16)
at settle (settle.Js:17)
at XMLhttprequest.handleLoad (xhr.Js:62)

组件


    // /////////////////////////////////////////
    // Form Events,Listeners,and err handlers
    // ////////////////////////////////////////
    onFormsubmit = (event) => {
        event.preventDefault();
        if (this.state.auctionEnded === falsE) {
            return;
        };
    };

    onbuttonClick = async (event) => {
        if (this.state.auctionEnded === falsE) {
            // Current BIDder and Price set to state to be stored in DB
            this.currentPrice = this.state.auctionPrice + .01
            this.formattednum = parsefloat(this.currentPricE)
            this.setState({ highBIDder: 'jonny',auctionPrice: this.formattednum })

            await axios.post(`http://localhost:3000/auction-items/${this.state.auctionID}/edit`,{
                highBIDder: this.state.highBIDder,auctionPrice: this.state.formattednum
            },{
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                }
            })
                .then(function (responsE) {
                    console.log(responsE);
                })
                .catch(function (error) {
                    console.log(error);
                });
            
            // Clock reset
            
            this.reset()
        }
    }

Server.Js


    router.post('/:ID/edit',function(req,res){
        AuctionItems.findByID(req.params.ID)
        .then(auctionItem => {
            auctionItem.highBIDder = req.body.highBIDder
            auctionItem.auctionPrice = parsefloat(req.body.auctionPricE)

            auctionItem.save()
                .then(() => {
                    console.log('Done Auction')
                    res.Json('Auction updated!')
                })
                .catch(err => res.status(400).Json('Error: ' + err));
            })
            .catch(err => res.status(400).Json('Error: ' + err));
        });

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的MERN 堆栈,axios 将当前状态发布到 DB 错误 400 错误请求全部内容,希望文章能够帮你解决MERN 堆栈,axios 将当前状态发布到 DB 错误 400 错误请求所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。