1 回答
TA贡献1847条经验 获得超11个赞
谢谢我使用 webpack encore 成功了。帮助 :
安装 Fos jsrouting 包
step 1 : expose your route in your controller otherwise you have to modify the file: fos_js_routes.json in the public folder or rename the route
/**
* @Route("/country", **options={"expose"=true},** name="ajaxCountry")
**/
step 2 :
import Routing from '../../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';
const routes = require('../../../public/js/fos_js_routes.json');
Routing.setRoutingData(routes);
var formData = new FormData();
var urlAjax = Routing.generate('yourRoute');
fetch(urlAjax, {
method: 'POST',
body: formData
})
.then(function (response) {
return response.json();
})
.then(function (message) {
...
step 3 : in your terminal
php bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json
再见
添加回答
举报