My spring application is working fine on my local machine and deploys successfully on both Tomcat 8 and 9. However, when trying to post data with AJAX using Axios, I keep receiving a 404 error message. I have double-checked the URL on both the front-end and back-end, and everything seems to be correct.
CONTROLLER
@Controller
public class StudentController {
@Autowired
StudentSearchRepo studentSearchRepo;
@ResponseBody
@RequestMapping(value="/csis/ajax/student/search", method = RequestMethod.POST)
public StudentSearch searchStudent(@RequestBody Student student)
{
StudentSearch studentSearch = studentSearchRepo.findByStudentNumber(student.getStudentNumber());
if(studentSearch == null)
{
StudentSearch studentSearch1 = new StudentSearch();
studentSearch1.setApplicantNumber(1);
return studentSearch1;
}
return studentSearch;
}
}
JAVASCRIPT
<script th:inline="javascript">
new Vue({
el: "#student_details",
data:{
studentNumber: '',
search_content: false,
result_set: false,
student: []
},
methods:{
searchStudent: function () {
this.search_content = false;
axios.post("/csis/ajax/student/search",{
studentNumber: this.studentNumber
}).then(response =>{
if(response.data.applicantNumber === 1)
{
this.search_content = false;
this.result_set = true;
}else {
this.search_content = true;
this.result_set = false;
this.student = response.data
}
}).catch( error =>{
console.log(error)
})
}
}
})
</script>
Any assistance would be greatly appreciated as I believe there might be something I am overlooking.