Javascript Silex和Ajax通信问题
我与Silex的ajax通信有问题。 因此,我使用Ajax创建了一个JS文件,如下所示:Javascript Silex和Ajax通信问题,javascript,jquery,ajax,silex,Javascript,Jquery,Ajax,Silex,我与Silex的ajax通信有问题。 因此,我使用Ajax创建了一个JS文件,如下所示: $.ajax({ type: "POST", cache: false, async: 'true', url: "/get-taxonomy-details", success: function(html){ if(html != '') { console.log(html); } }, e
$.ajax({
type: "POST",
cache: false,
async: 'true',
url: "/get-taxonomy-details",
success: function(html){
if(html != '') {
console.log(html);
}
},
error: function(x,e){
console.log('Ajax', e, x);
}
});
$factory->post('/get-taxonomy-details', function() {
return 'ok';
});
然后,在“connect(Application$app)”中已经存在的Silex控制器中,我添加了如下路由:
$.ajax({
type: "POST",
cache: false,
async: 'true',
url: "/get-taxonomy-details",
success: function(html){
if(html != '') {
console.log(html);
}
},
error: function(x,e){
console.log('Ajax', e, x);
}
});
$factory->post('/get-taxonomy-details', function() {
return 'ok';
});
我收到一个找不到路由的错误:
POST http://www.my_site.dev/get-taxonomy-details 404 (Not Found)
这只是我想要实现的一个一般性示例。
因为我是新来的Silex我不确定我错过了什么
我在读Silex doc,我也试过使用GET。
谢谢你能告诉我们$factory从哪里来吗?你有没有试着走捷径?如果不在路由中附加index.php文件,它是否可以工作?使用network选项卡中的inspect元素,执行ajax调用并查看URL指向的位置。这真的是你的结构吗?你能告诉我们$factory从哪里来吗?你有没有试着走捷径?如果不在路由中附加index.php文件,它是否可以工作?使用network选项卡中的inspect元素,执行ajax调用并查看URL指向的位置。这真的是你的结构吗?