Home > Blockchain >  I'm trying to route directly to the route with ajax in Laravel, but I'm getting an error
I'm trying to route directly to the route with ajax in Laravel, but I'm getting an error

Time:10-14

I'm trying to route directly to the route with ajax in Laravel, but I'm getting an error. I'm taking my first crack at Ajax with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string back that looks like this: /Date(1224043200000)/ From someone totally new.

$(document).ready(function() {
        var delayInMilliseconds = 3000;
        var url = '{{ route('urun_durum_kontrolu') }}';
        var data = {
            "_token": '{{ csrf_token() }}',
        };
        setTimeout(function() {
            $.ajax({
                type: "post",
                url: url,
                data: data,
                success: function(response) {}
            });
        }, delayInMilliseconds);
    });

CodePudding user response:

url = url.replace();

You need to use replace.

$(document).ready(function() {
            var delayInMilliseconds = 3000;
            var url = '{{ route('urun_durum_kontrolu') }}';
            url = url.replace();
            var data = {
                "_token": '{{ csrf_token() }}',
            };
            setTimeout(function() {
                $.ajax({
                    type: "post",
                    url: url,
                    data: data,
                    success: function(response) {}
                });
            }, delayInMilliseconds);
        });

CodePudding user response:

You have to try URL String like "/your_url" in ajax

 $(document).ready(function() {
        var delayInMilliseconds = 3000;
        var url = '/your_URL';
        url = url.replace();
        var data = {
            "_token": '{{ csrf_token() }}',
        };
        setTimeout(function() {
            $.ajax({
                type: "post",
                url: url,
                data: data,
                success: function(response) {}
            });
        }, delayInMilliseconds);
    });
  • Related