问题描述
这是我的应用程序/routing.yml
this is my app/routing.yml
resource: "@FrontendBundle/Resources/config/routing.yml"
prefix: /{_locale}/
requirements:
_locale: en|es
后端捆绑:
resource: "@BackendBundle/Resources/config/routing.yml"
prefix: /{_locale}/app
requirements:
_locale: en|es
fos_js_routing:
资源: @ FOSJsRoutingBundle / Resources / config / routing / routing.xml
fos_js_routing: resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
这是我的BackendBundle\资源\Config\routing.yml
and this is my BackendBundle\Resources\Config\routing.yml
pattern: /getModelsFromMake/{idMake}
defaults: { _controller: BackendBundle:Backend:getModelFromMake }
options:
expose: true
我的问题是当我做aj像这样的ax调用:
and my problems is when i do a ajax call like this:
url: Routing.generate('getModelsFromMake'),
data: {
idMake: $('#make').val(),
},
dataType: "json",
success: function(data) { console.log("All OK"); },
error: function() { console.log("ERROR"); }
});
Chrome检验员告诉我:
the chrome inspector tell me:
Uncaught Error: The route "getModelsFromMake" requires the parameter "_locale".
有什么解决办法吗?
编辑1:
在我的布局中,我这样:
in my layout I have this:
<script type="text/javascript" src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
编辑2:
如果我运行命令 php app / console fos:js-routing:debug,我会得到:
if I run the command "php app/console fos:js-routing:debug" I get this:
Name Method Pattern
getModelsFromMake ANY /{_locale}/app/getModelsFromMake
推荐答案
尝试在您的ajax之前插入此代码段
Try to insert this snippet of code before your ajax
<script>
var locale= {{ app.request.locale }} ;
</script>
并按如下所示修改脚本
$.ajax({ type: "POST",
url: Routing.generate('getModelsFromMake', array('_locale' => locale)),
data: {
idMake: $('#make').val(),
},
dataType: "json",
success: function(data) { console.log("All OK"); },
error: function() { console.log("ERROR"); }
});
这篇关于Symfony,fos_js_routing和“ _locale”问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!