how to Make Http request from reactjs ?

前端 未结 3 559
生来不讨喜
生来不讨喜 2021-01-15 18:41

I am using react js as front end and zf3 as a backend in my ToDo application. I put all my React folder and files in public folder of Zend project. As of now, it is just S

3条回答
  •  耶瑟儿~
    2021-01-15 19:44

    install axios
    
    $ npm install axios
    
    
    import axios
    
    import axios from 'axios';
    
    get request
    
    axios.get('api url').then(function (response) {
        console.log(response);
    }).catch(function (error) {
        console.log(error);
    });
    
    
    post request
    
    var body = {
        firstName: 'testName',
        lastName: 'testLastName'
    };
    
    axios.post('api url',body).then(function (response) {
        console.log(response);
    }).catch(function (error) {
        console.log(error);
    });
    

提交回复
热议问题