我从 Laravel 和 Ajax 开始,当然我有一个问题:-(
这是一个运行良好的脚本
$.ajax({
type : 'GET',
url : 'getListeGenreCategorieAjax/'+$(this).val() ,
dataType : 'html',
beforeSend : function() {$('#waiting').show(); }, // faire apparaitre l'image d'attente
success : function(data){
$('#id_genre').html(data); // affichage des résultats dans le select
$("#id_genre option[value='"+id_genre_cache+"']").attr("selected", true);
$('#waiting').hide();
}
});
当我运行它时,我在 firebug 中看到了路线:
http://localhost/predami_new/public/getListeGenreCategorieAjax/VIDEO
完美!我收到回复,一切正常。
现在我在另一个页面上做了同样的事情,但它不再起作用了。现在看到的路线是:
http://localhost/predami_new/public/formulaire_produit/getListeGenreCategorieAjax/VIDEO
它不起作用,因为有这个“formulaire_produit/”已插入到 route 。
我的问题:为什么这个路由在另一个页面上修改?我必须做什么 ?
非常感谢您的反馈。祝你有美好的一天。
多米尼克
最佳答案
这是由于您在url
参数中使用了相对url。当您位于 http://localhost/predami_new/public/
页面时,它会附加 'getListeGenreCategorieAjax/'+$(this).val()
,当您位于页面 http://localhost/predami_new/public/formulaire_produit/
它也附加了相同的内容。您应该使用绝对网址:
url : '{{URL::to('/')}}/getListeGenreCategorieAjax/'+$(this).val()
或者如果您的ajax代码不在blade文件中:
url : '/predami_new/public/getListeGenreCategorieAjax/'+$(this).val()
关于jquery - LARAVEL 与 AJAX ,修改路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28657461/