Silex:jQuery AJAX请求引发异常-未找到"GET ..."的路由 [英] Silex: jQuery AJAX request throws exception - No route found for "GET ..."
本文介绍了Silex:jQuery AJAX请求引发异常-未找到"GET ..."的路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在tr click上进行ajax调用:
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');
我的控制器操作:
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")
推荐答案
错误的http请求方法:
您正在使用jQuery发送 GET 请求,而不是 POST 请求.
You're sending a GET request instead of a POST request with jQuery.
$.ajax()
默认情况下执行 GET 请求.
$.ajax()
performs a GET request by default.
Silex引发异常是因为您尚未为 GET 定义路由,而仅为 POST 定义了路由.
Silex throws the exception because you have not defined a route for GET but only for POST.
$app->post('..')
解决方案:将请求类型添加到$.ajax
solution: add the request-type to $.ajax
$.ajax({
type: "POST",
// ...
});
这篇关于Silex:jQuery AJAX请求引发异常-未找到"GET ..."的路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文