2

I've recently deployed my Symfony project to a production environment. Everything is loading except the .getJSON jquery function. This returns a 404 error. Now the strange part is that it works localy.

This is the code.

Jquery:

$.getJSON('/ClientThisYear', function(response) {

Routing:

app:
   resource: "@AppBundle/Controller"
   type:     annotation

AppBundle/Controller:

/**
 * @Route("/ClientThisYear")
 */
public function ClientThisYear()
{
    $em = $this->getDoctrine()->getManager();
    $ClientStats = $em->getRepository('ClientBundle:Client')
        ->ClientStats();
    $ClientArray = array();
    foreach($ClientStats[0] as $Arr)
    {
        $ClientArray[] = $Arr;
    }
    $Return = json_encode($ClientArray);
    return new Response($Return,200,array('Content-Type'=>'application/json'));
}

So it worked for a while but after a while it started returning a 404 error.

What i've tried is:

  • Clearing the cache.
  • Deployed it again from local.

Error log :

[2015-12-30 14:50:43] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /ClientThisYear" (from "http://example.nl/web/admin")" at /home/**/**/var/cache/prod/classes.php line 2377 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException(code: 0): No route found for \"GET /ClientThisYear\" (from \"http://example.nl/web/admin\") at /home/**/**/var/cache/prod/classes.php:2377, Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException(code: 0):  at /home/**/**/var/cache/prod/appProdUrlMatcher.php:255)"} []

Can someone please help me with this

8
  • Have you tried it in dev mode? Commented Dec 30, 2015 at 14:44
  • yes i've tried it locally in the dev mode and prod mode. When i did that, there wasn't any errors and it showed the records correctly. The problem is only on the server. It is a exact copy of the local one. Commented Dec 30, 2015 at 14:47
  • Does you local path prefix match the one from production? For example http://localhost/myapp/ClientThisYear vs http://mywebsite/ClientThisYear. Can you invoke the path via browser at all? What does the log say about error? Or maybe production does not have mod_rewrite enabled? Commented Dec 30, 2015 at 14:49
  • It has the same path as the /admin route in the same controller. And that is shown correctly . So i think that the path is set correctly. I'll edit my question with the error log Commented Dec 30, 2015 at 14:54
  • The command - 'php app/console router:debug' may reveal a hint Commented Dec 30, 2015 at 15:09

1 Answer 1

1

Using route in Javascript may require FOSJsRouting.

This bundle allow you to use your route with javascript

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.