Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mbpp's avatar
Level 3

ajax post different route

Hi there, there is happening a bug in my app that isnt the first time that happen to be, i cant figure out why is doing it. I have a post request being made in a specific route, but in my app, instead making the ajax call to my specific url is send to the current url from tha page. My ajax code:

$.ajax({
                    method: 'POST',
                    async: false,
                    url: '/galleries/heatMap/'.idGallery,
                    type: 'POST',
                    data: {img: url, _token: token, idGallery: idGallery, productStat: productStat, tagStat: tagStat}
                })
                .done(function(msg){
                    console.log("Save HeatMap");

                    tagStat = {
                        title: "",
                        clicks:0,
                        product_id:0
                    };
                    productStat = {
                        clicks: 0,
                        product_id:0
                    };



                }).fail(function() {
                console.log("Error ocurred");

            });

My current url where im making the post is: http://domain.com/models/1/embed/

And for some reason the post is being made to '../models/1/embed/', instead the url of the ajax. Does someone have a idea what is happening?

0 likes
7 replies
gabrielbuzzi's avatar

Maybe this works.

php artisan route:clear

and the concat in the JS is a + not a .

 url: '/galleries/heatMap/' + idGallery,

tomopongrac's avatar

Try remove type

$.ajax({
                    method: 'POST',
                    url: '/galleries/heatMap/' + idGallery,
                    data: {img: url, _token: token, idGallery: idGallery, productStat: productStat, tagStat: tagStat}
                })
                .done(function(msg){
                    console.log("Save HeatMap");

                    tagStat = {
                        title: "",
                        clicks:0,
                        product_id:0
                    };
                    productStat = {
                        clicks: 0,
                        product_id:0
                    };



                }).fail(function() {
                console.log("Error ocurred");

            });

mbpp's avatar
Level 3

Sorry guys, im really sorry was very stupid from my part, the issue was the route, the route that was on the ajax doesnt exist, i had the idea i already updated or jsut forgot to check, im really sorry wasting your guys time :S

Please or to participate in this conversation.