在POST请求React中无法发送JSON响应

时间:2018-01-09 18:54:20

标签: javascript json reactjs http-post

单击时,我有一个提交按钮,必须将一组JSON响应发送到服务器。下面是我的代码片段。虽然没有错误但应用程序不会向服务器发送json响应。

class Slide extends Component {

    constructor() {
        super();
        this.state = {visible: false};
        this.state = {
            options: [{key: 0, text: 'None', value: 0},
                {key: 1, text: 'Chord Daigram', value: 1},
                {key: 2, text: 'Pie Chart', value: 2},
                {key: 3, text: 'Heat Map', value: 3},
                {key: 4, text: 'Bar Chart', value: 4}]
        };


        this.toggleVisibility = () => this.setState({visible: !this.state.visible}),
            this.clearSelection = () => this.setState({options: this.state.options});

    }

    componentWillMount() {
        this.update();
    }

    update() {
        axios({
            method: 'post',
            url: 'http://localhost:8080/interact/ID/update',
            data: {
                ID: 'KE-0604',
                visibility: 'False'
            }

        });
    }


    render() {
        const {visible, clearSelection} = this.state
        return (
            <div>
                <Sidebar.Pushable as={Segment}>
                    <div className="ui icon Button">
                        <Button basic floated='right' icon onClick={this.toggleVisibility}><Icon name='align justify'/></Button>
                    </div>
                    <Sidebar
                        as={Menu}
                        animation='overlay'
                        width='very wide'
                        direction='right'
                        visible={visible}
                        icon='labeled'
                        vertical>
                        <Segment>
                            <div>
                                <Container textAlign='right'>
                                    <Icon onClick={this.toggleVisibility} floated='right'>
                                        <Icon name='close'
                                              size='large'/>
                                    </Icon>
                                </Container>
                            </div>
                            <br/>
                            <div floated='right'>
                                <Dropdown placeholder='Select Visualization' selection options={options}/>
                            </div>
                            <br/>
                            <Combobox/>
                            <br/>
                            <Button primary floated='left' size='small' onClick={this.update}>Submit </Button>
                            <Button positive floated='left' size='small' onClick={options}>Reset</Button>
                            <br/>
                            <br/>
                        </Segment>
                    </Sidebar>
                    <Sidebar.Pusher>
                        <Chord/>
                    </Sidebar.Pusher>
                </Sidebar.Pushable>
            </div>
        )
    }
};

export default Slide;

单击提交按钮后,服务器将通过更改可见性发送一组新数据。在我的代码中,单击提交按钮后无效。

0 个答案:

没有答案