How to make a rest post call from ReactJS code?

前端 未结 9 1935
一生所求
一生所求 2020-12-02 05:28

I am new to ReactJS and UI and I wanted to know how to make a simple REST based POST call from ReactJS code.

If there is any example present it would be really h

9条回答
  •  渐次进展
    2020-12-02 06:07

    Here is an example: https://jsfiddle.net/69z2wepo/9888/

    $.ajax({
        type: 'POST',
        url: '/some/url',
        data: data
      })
      .done(function(result) {
        this.clearForm();
        this.setState({result:result});   
      }.bind(this)
      .fail(function(jqXhr) {
        console.log('failed to register');
      });
    

    It used jquery.ajax method but you can easily replace it with AJAX based libs like axios, superagent or fetch.

提交回复
热议问题