Hey povilas, I'm learning react with laravel in weekends, so first of all thanks for making it.
While developing a web app, I was stuck for sometime when I was using fetch, I was basically trying to send a post request using fetch but send me 302 and when used axios it give me expected result. I researched it on google but i didn't get that why it was happening. If you know that why this happend than please share me. For the ref. i'm sharing my code snippet. Thanks in advance.
Hi, not sure, 302 means that validation error treated it as a web request and redirected to the "previous page". So something is wrong with your headers. Try adding "Accept: application/json"
Hey povilas, I'm learning react with laravel in weekends, so first of all thanks for making it.
While developing a web app, I was stuck for sometime when I was using fetch, I was basically trying to send a post request using fetch but send me 302 and when used axios it give me expected result. I researched it on google but i didn't get that why it was happening. If you know that why this happend than please share me. For the ref. i'm sharing my code snippet. Thanks in advance.
return axios.post(API_PREFIX+'/api/v1/user/register', data, { headers: { 'Content-Type': 'application/json', } })
when this hit to server response was 422
but when i use below code it's sending me 302
fetch(API_PREFIX+'/api/v1/user/register', { method: 'POST', body: JSON.stringify(data), headers: { 'Content-Type': 'application/json', } })
Hi, not sure, 302 means that validation error treated it as a web request and redirected to the "previous page". So something is wrong with your headers. Try adding "Accept: application/json"
Maybe related article: Laravel: API Error Shows HTML and not JSON - How To Fix
Hey povilas, thanks for the response. This error is only occur when i use fetch, I'll try your suggestion thanks!!