Failed to load resource: the server responded with a status of 404 (not found react)

공부하는 비오

  • 분류 전체보기 (232)
    • 이론공부 (7)
    • Error (25)
    • JavaScript (60)
    • TypeScript (7)
    • React (23)
      • React 관련 라이브러리 (5)
    • ReactNative (4)
    • Redux (23)
    • Next.js (9)
    • Firebase (12)
    • Node (17)
      • Express (12)
    • Sequelize (12)
    • AWS (8)
    • HTML & CSS (7)
    • jQuery (16)
      • Ajax (3)

POWERED BY TISTORY


Error

비오스터딩 2020. 11. 4. 12:37

Failed to load resource: the server responded with a status of 404 (not found react)

구글링해보니 해당 에러는 데이터가 없기때문에 생기는 에러였다.

내 경우엔 json파일을 받아오지 못했는데,

코드짤때 상대경로로 작성했기 때문이었다.

해결방법

상대경로를 절대경로로 바꿔준다.

즉 웹페이지 url을 넣어줌.

'Error' 카테고리의 다른 글

ESlint _ Parsing error: Unexpected token  (0) 2020.12.08
Error: 'react-scripts'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는배치 파일이 아닙니다.  (0) 2020.12.02
Error: ELIFECYCLE  (0) 2020.11.20
[React] Error: Maximum update depth exceeded.  (0) 2020.11.04
Failed to load resource: the server responded with a status of 404 ( ) __json file  (0) 2020.11.04
[Terminal Error]FullyQualifiedErrorId : UnauthorizedAccess  (0) 2020.11.03

  • Failed to load resource: the server responded with a status of 404 (not found react)
    Error: 'react-scripts'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는배치 파일이 아닙니다.
  • Failed to load resource: the server responded with a status of 404 (not found react)
    Error: ELIFECYCLE
  • Failed to load resource: the server responded with a status of 404 (not found react)
    [React] Error: Maximum update depth exceeded.
  • Failed to load resource: the server responded with a status of 404 (not found react)
    [Terminal Error]FullyQualifiedErrorId : UnauthorizedAccess

Secret

이전 1 ··· 20 21 22 23 24 25 다음


Jump to answer

I am having trouble navigating to the right path after editing a form in React. The web page refreshes and logs me out of the site despite having no error when updating. The console has this error:

Failed to load resource: the server responded with a status of 404 (Not Found)

Here is my front end code:

import React, {useContext, useState, useEffect} from 'react' import { UserContext, UserTypeContext } from '../Helper/Context'; import { Form, Button, Card } from 'react-bootstrap'; import Axios from 'axios'; import { useHistory } from 'react-router-dom'; function LecturerEditProject(){ const history = useHistory(); const {userId, setUserId} = useContext(UserContext); const {type, isUserType} = useContext(UserTypeContext); const [projectCode, setProjectCode] = useState(""); const [projectTitle, setProjectTitle] = useState(""); const [projectInformation, setProjectInformation] = useState(""); const [collaboratorId, setCollaboratorId] = useState(""); const updateProject = () => { Axios.put(`http://localhost:3001/lecteditproject/${projectCode}`,{ projectId: projectCode, projectTitle: projectTitle, projectInformation: projectInformation, collaboratorId: collaboratorId, }).then((response) => { if(response){ window.alert('Your project has been updated!'); history.push(`/lecturer/${userId}/yourproject`); } else{ window.alert('Update is unsuccessful!'); } }) } return( <div className="d-flex justify-content-center"> <Card style={{ width: '70%' }}> <Form onSubmit = {updateProject} className = "m-3 p-5"> <h3>Edit Project</h3> <hr/> <Form.Group className="mb-3" controlId="projectTitle"> <Form.Label>Project Title</Form.Label> <Form.Control type="text" placeholder="Enter your project title here" onChange = {(event) => { setProjectTitle(event.target.value); }} defaultValue = {projectTitle} /> </Form.Group> <Form.Group className="mb-3" controlId="projectInformation"> <Form.Label>Project Information</Form.Label> <Form.Control as="textarea" rows={3} placeholder="Enter your project information here" onChange = {(event) => { setProjectInformation(event.target.value); }} defaultValue = {projectInformation} /> </Form.Group> <Form.Group className="mb-3" controlId="projectCollaborator"> <Form.Label>Collaborator</Form.Label> <Form.Control type="text" placeholder="Enter your project collaborator ID here" onChange = {(event) => { setCollaboratorId(event.target.value); }} /> </Form.Group> <div className = "d-flex flex-end justify-content-end align-items-end mt-3"> <Button className = "d-flex flex-end justify-content-end align-items-end" variant="primary" type="submit"> Update </Button> </div> </Form> </Card> </div> )

My Node.js Axios put request is as below:

app.put("/lecteditproject/:projectid", (req,res) => { // upload.single('userImage') const projectId = req.body.projectId; const projectTitle = req.body.projectTitle; const projectInformation = req.body.projectInformation; const collaboratorId = req.body.collaboratorId; try{ const updateProject = "UPDATE project SET project_title = ?, project_information = ?, representative_id = ? WHERE project_id = ?;" db.query(updateProject, [projectTitle, projectInformation, collaboratorId, projectId], (err, result) => { if(err){ console.log("Error: ", err); } else{ res.send(result); } }) } catch(err){ console.log(err); } } )

Anyone can please, please help me with this problem? I have been stuck on this part for days. The update is successful but it logs me out. Thank you.

Answer

Why page reload is the default behavior of the form tag you have to prevent that default behavior by doing this this event.preventDefault(); in updateProject function this will revolve you refresh issue now see that you get the response from the API still not then I suggest try checking with postman that you get a response or not

const updateProject = async (event) => { event.preventDefault(); try { const res = await Axios.put( `http://localhost:3001/lecteditproject/${projectCode}`, { projectId: projectCode, projectTitle: projectTitle, projectInformation: projectInformation, collaboratorId: collaboratorId, } ); window.alert("Your project has been updated!"); history.push(`/lecturer/${userId}/yourproject`); } catch (error) { console.log(error); window.alert("Update is unsuccessful!"); } };