Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mokhudari's avatar

Uploading files using vue and laravel

I'm trying to upload a file using axios to Laravel backend, on my local machine everything works like a charm but on live server somehow AXIOS POST not triggering the controller!!

0 likes
5 replies
martinbean's avatar

@mokhudari Sorry to hear that.

Maybe try some steps to diagnose the problem, such as checking your log file for exceptions, or using your browser’s dev tools to monitor AJAX requests and see if they fail and if they do, what the response is?

mokhudari's avatar

@martinbean thanks for the reply , there is no fault with response but there is a difference though , on local machine says post 302 while on server says 303 is there a problem here ?

mokhudari's avatar

@martinbean

 const importData = async fileName=> {
    const config = {
      headers: {
        'Content-Type': 'multipart/form-data',
      },

    }

  
    let data = new FormData()
 
    data.append('file', fileName)
  
    console.log(fileName)
 
    
    axios.post('/api/importData/', data, config) 
      .then(response => {
        
        router.push({ name: 'prs' })
     
      })

      .catch(function (err) {
        console.log(err)
       
      })
 
  }
martinbean's avatar

@mokhudari You need to add a Accept header with a value of application/json to tell Laravel you want JSON responses and not redirects.

Please or to participate in this conversation.