部署构建React项目后,PHP响应为空

时间:2019-11-04 02:11:57

标签: reactjs axios

部署我的react项目的build文件夹后,我尝试登录,但是我注意到该会话为空。我的项目的输出大部分是错误的,因为每个页面都需要会话。我尝试调试,发现我的PHP文件没有数据响应。

请问我的代码有什么问题。 在这里。

handleClick = event =>  {
event.preventDefault();

if (this.validateForm()) {
  let loginform = document.getElementById('login');
  let formData = new FormData(loginform);
  formData.append('username',this.state.username)
  formData.append('password',this.state.password)
  formData.append('company',this.state.company)
  formData.append('division',this.state.division)

  axios({
  method: 'post',
  url: this.getHostname()+'/new_vehicle_management/src/components/php/login.php',
  data: formData,
  config: 
  {
    //headers:{'Content-Type':'multipart/form-data'
    headers: {
      "Access-Control-Allow-Origin": '*',
      "Access-Control-Allow-Credentials": 'true', 
      "Access-Control-Allow-Methods":'GET, POST, PATCH, PUT, DELETE, OPTIONS',
      "Content-Type": "multipart/form-data",
      Accept: "application/json"
  }}
  })
  .then(function (response) {
          if (response.data === "failed") {
           alert("Connection Failed.")
          }else if (response.data === "No Company") {
            alert("Company does not exist.")
           }else if (response.data === "No Division") {
            alert("Division does not exist.")
           }else if (response.data === "No User") {
            alert("Username does not exist.")
           }else if (response.data === "Not Match") {
            alert("Username and Password does not match.")
           }else if(response.data === "No Record"){
            alert("Invalid Credentials.");
           }
           else{
            alert("Login Successfully")
            localStorage.setItem('data', JSON.stringify(response.data))
            localStorage.setItem('user_id', JSON.stringify(response.data.user_id))
            localStorage.setItem('user', JSON.stringify(response.data.user_full_name))
            localStorage.setItem('div_id', JSON.stringify(response.data.div_id))
            localStorage.setItem('comp_id', JSON.stringify(response.data.comp_id))
            window.location = "/menu"
           }
        })
        .catch(function (response) {
            //handle error
            console.log(response)
        });
}         
}

0 个答案:

没有答案