代码之家  ›  专栏  ›  技术社区  ›  abu abu

reactjs中ajax请求中的问题

  •  0
  • abu abu  · 技术社区  · 6 年前

    我正在尝试使用reactjs作为前端框架和laravel 5.6作为后端框架开发一个应用程序。我试图发送如下ajax请求

    import Auth from '../services/Auth';
    
    var address_data = {
            name        :'foysal',                    
            address     :'foysal',
            telephone_no:'foysal',
            email       :'foysal',
    }
    
    
    
    fetch('http://127.0.0.1:8000/api/addresses/store/',address_data, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
                'Authorization': 'Bearer ' + Auth.getToken(),
            },
            body: JSON.stringify()
        })
        .then((response) => response.json())
        .then((responseData) => {
            console.log(responseData);
        })
    

    我的错误越来越少了

    enter image description here

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  1
  •   Suresh Prajapati    6 年前

    尝试将获取请求更改为启动 POST 像这样的动作动词

    fetch('http://127.0.0.1:8000/api/addresses/store/', {
      method: 'POST',
      headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + Auth.getToken(),
      },
      body: JSON.stringify(address_data)
    }).then(res => res.json())
    .catch(error => console.error('Error:', error))
    .then(response => console.log('Success:', response));