问题
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:
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",
// ...
});
来源:https://stackoverflow.com/questions/22011254/silex-jquery-ajax-request-throws-exception-no-route-found-for-get