weixin_33728708 2018-06-06 16:41 采纳率: 0%
浏览 31

使用symfony进行Ajax路由

I am using symfony and twig and trying to route to a controller function that exists, using ajax. The route I am trying to get to seems to be appended to the current route (page) that is calling the ajax. What is causing this and what am I doing wrong? I am intermediate at this. Thanks in advance for your efforts.

The ajax looks like;

    $.ajax({url: "{{ path('material-stock_check') }}/" + quoteRing.materialId + "/" + quoteRing.gaugeId + "/" + decimal, success: function (results) {
            if (results.length === 0) {
                quoteRing.findStripWidthAlternates();

            }
        }});

and the controller looks like

    /**
 * Check if the strip width is in the Inventory
 * @Route("/check/{materialId}/{gaugeId}/{decimal}", defaults={"materialId" = 0, "gaugeId" = 0, "decimal" = 0}, name="material-stock_check")
 * @Method("GET")
 */
public function checkStripWidthAction (Request $request, $materialId, $gaugeId, $decimal)
{
    $em = $this->getDoctrine()->getManager();

    $materialStocks = $em->getRepository('UniflyteBundle:MaterialStock')->findAllByParams(['widthDecimal' => $decimal, 'materialId' => $materialId, 'gaugeId' => $gaugeId]);

    if ($request->isXmlHttpRequest()) {
        if (null === $materialStocks) {
            return new JsonResponse('failure');
        }
        $results = [];
        foreach ($materialStocks as $result) {
            $results[] = [
              'gaugeId'    => $result->getGauge()->getId(),
              'materialId' => $result->getMaterial()->getId()
            ];
        }

        return new JsonResponse($results);
    }
}

When the ajax is called I am getting

No route found for "GET /uniflyte/quote-ring/new/%7B%7B%20path('material-stock_check')%20%7D%7D/93/347/3.45" (from "http://localhost:8088/uniflyte/quote-ring/new/rolled-ring")

The ajax route looks appended to the existing route. What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • weixin_33691598 2018-06-06 22:30
    关注

    Have you declare the path in route file

    评论

报告相同问题?