dtsps00544 2014-02-25 10:23
浏览 43
已采纳

Silex:jQuery AJAX请求抛出异常 - 找不到“GET ...”的路由

I'm trying to make an ajax call on tr click like this:

$.ajax({
    type: "GET",
    url: "/segments/ajaxGetHostsSegment",
    data: {
        deelgebied: deelgebiedid
    },
    success: function( data ) {
        // CHECK ID'S WITH ID'S IN FORM AND CHECK CHECKBOXES
    },
    error: function (xhr, ajaxOptions, thrownError) {
        console.log(xhr.status);
        console.log(thrownError);
    }
})

In my routes file I have:

$app->get('/segments/ajaxgethostssegment', 'Segments\Controller\IndexController::ajaxGetHostsSegment')->bind('segments.gethosts');

My Controller action:

public function ajaxGetHostsSegment(Application $app, Request $request)
{
    $deelgebied = $request->request->get('data');
    var_dump($deelgebied);
    die();
}

But I always get the error:

No route found for "GET /segments/ajaxGetHostsSegment" (from "http://mext-pst.localhost:8080/segments/view/PSS1400023")
  • 写回答

1条回答 默认 最新

  • duanlu5055 2014-02-25 10:33
    关注

    wrong http request method:

    You're sending a GET request instead of a POST request with jQuery.

    $.ajax() performs a GET request by default.

    Silex throws the exception because you have not defined a route for GET but only for POST.

    $app->post('..')
    

    solution: add the request-type to $.ajax

    $.ajax({
        type: "POST",
        // ...
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog