gpt4 book ai didi

php - 调用 .getJSON 时 Symfony 返回 404 错误

转载 作者:行者123 更新时间:2023-12-01 04:42:54 26 4
gpt4 key购买 nike

我最近将我的 Symfony 项目部署到生产环境中。除了 .getJSON jquery 函数之外,所有内容都正在加载。这会返回 404 错误。现在奇怪的是它在本地工作。

这是代码。

Jquery:

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

路由:

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

应用程序包/ 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'));
}

所以它工作了一段时间,但过了一会儿它开始返回 404 错误。

我尝试过的是:

  • 清除缓存。
  • 从本地再次部署。

错误日志:

[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)"} []

有人可以帮我解决这个问题吗

最佳答案

在 Javascript 中使用路由可能需要 FOSJsRouting .

此 bundle 允许您通过 JavaScript 使用路线

关于php - 调用 .getJSON 时 Symfony 返回 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34531573/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com