Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 出现在url中的查询_Javascript_Reactjs_React Router - Fatal编程技术网

Javascript 出现在url中的查询

Javascript 出现在url中的查询,javascript,reactjs,react-router,Javascript,Reactjs,React Router,我正在使用HashRouter在React上制作一个应用程序。在应用程序中,我有一个带有输入的表单,在用户提交数据后,一些数据会显示在URL中,如下所示: handleSubmit() { const { userUrl } = this.props; let { street_address, state, city, zip, email, phone, avatar, about_message, proximity } = this.state;

我正在使用HashRouter在React上制作一个应用程序。在应用程序中,我有一个带有输入的表单,在用户提交数据后,一些数据会显示在URL中,如下所示:

    handleSubmit() {
        const { userUrl } = this.props;
        let { street_address, state, city, zip, email, phone, avatar, about_message, proximity } = this.state;

        if (this.props.user.title === 'caregiver') {
            axios.put('/update/profile', {
                street_address,
                state,
                city,
                zip,
                email,
                phone,
                avatar: userUrl.length ? userUrl : avatar,
                about_message,
                proximity
            })
                .then(response => {
                    console.log(response);
                    this.setState({
                        street_address,
                        state,
                        city,
                        zip,
                        email,
                        phone,
                        avatar,
                        about_message,
                        proximity
                    })
                })
                .catch(error => console.log(error))
        }
    }

当它应该是公正的

提交按钮上的函数只是获取所有值并发送到数据库,如下所示:

    handleSubmit() {
        const { userUrl } = this.props;
        let { street_address, state, city, zip, email, phone, avatar, about_message, proximity } = this.state;

        if (this.props.user.title === 'caregiver') {
            axios.put('/update/profile', {
                street_address,
                state,
                city,
                zip,
                email,
                phone,
                avatar: userUrl.length ? userUrl : avatar,
                about_message,
                proximity
            })
                .then(response => {
                    console.log(response);
                    this.setState({
                        street_address,
                        state,
                        city,
                        zip,
                        email,
                        phone,
                        avatar,
                        about_message,
                        proximity
                    })
                })
                .catch(error => console.log(error))
        }
    }

我发现问题部分出在表单中,因为一些输入具有name=”“属性,如果我去掉它,它将不会显示在URL中。但问号仍在显示。

您需要阻止表单进行默认提交:

handleSubmit(e) {
        e.preventDefault()
        const { userUrl } = this.props;
        let { street_address, state, city, zip, email, phone, avatar, about_message, proximity } = this.state;

        if (this.props.user.title === 'caregiver') {
            axios.put('/update/profile', {
                street_address,
                state,
                city,
                zip,
                email,
                phone,
                avatar: userUrl.length ? userUrl : avatar,
                about_message,
                proximity
            })
                .then(response => {
                    console.log(response);
                    this.setState({
                        street_address,
                        state,
                        city,
                        zip,
                        email,
                        phone,
                        avatar,
                        about_message,
                        proximity
                    })
                })
                .catch(error => console.log(error))
        }
    }

您需要阻止表单进行默认提交:

handleSubmit(e) {
        e.preventDefault()
        const { userUrl } = this.props;
        let { street_address, state, city, zip, email, phone, avatar, about_message, proximity } = this.state;

        if (this.props.user.title === 'caregiver') {
            axios.put('/update/profile', {
                street_address,
                state,
                city,
                zip,
                email,
                phone,
                avatar: userUrl.length ? userUrl : avatar,
                about_message,
                proximity
            })
                .then(response => {
                    console.log(response);
                    this.setState({
                        street_address,
                        state,
                        city,
                        zip,
                        email,
                        phone,
                        avatar,
                        about_message,
                        proximity
                    })
                })
                .catch(error => console.log(error))
        }
    }