I am calling a Symfony action via jQuery AJAX, however one of the actions is returning 404 and I am not sure why.
The Scenario.
An online system hosts a list of projects, these project can be added to a local system.
The user searches by Id and and if a project with that Id exists and they have not already added it the project will be added to their local system.
javascript
//CHECK IF EXTERNAL PROJECT CAN BE IMPORTED
$.get("/find-project/" + Id, function( data ) { << THIS ONE IS GOOD
if(data['status'] === false){
//PROJECT WITH THAT ID NOT FOUND
}else{
//PROJECT WITH THAT ID EXISTS
// HAVE YOU ALREADY ADDED THAT PROJECT
$.get("/check-project/" + Id, function(data){ << THIS RETURNS 404
if(data === false){
//PROJECT HAS NOT BEEN ADDED.. ADD IT
}else{
//PROJECT HAS ALREADY BEEN ADDED
}
})
}
});
Symfony Controller PHP
/**
* @Route("/find-project/{Id}", name="_findProject")
* @Method({"GET"})
*/
public function findProjectByIdAction($Id)
{
$project = $this->get('crm')->findProjectById($Id);
$status = $project ? true : false;
return new JsonResponse(array('status' => $status, 'project' => $project));
}
/**
* @Route("/check-project/{Id}", name="_checkProject")
* @Method({"GET"})
*/
//THIS FUNCTION CANNOT BE FOUND 404
public function checkIfProjectExistsAction($Id){
$query = $this->getDoctrine()->getRepository('AppBundle:Project')->findOneBy(array('Id' => $Id));
$cnt = count($query->getResult());
$cnt == 0 ? $status = false : $status = true ;
return new JsonResponse(array('status' => $status));
}
Already checked; Site is an available as route from route:debug in console
The requests return as
Remote Address:127.0.0.1:443 Request URL:https://localhost/check-project/12345 Request Method:GET Status Code:404 Not Found
Any help greatly appreciated
->getManager()
before you->getRepository()
? – D4V1Drm -rf app/cache/*
2. Check the scope ofId
variable in javascript maybe it's local and you are sending ajax call withundefined
– Alexandru Olaru