skip to Main Content

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);
    });

2

Answers


  1. 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);
            });
    
    Login or Signup to reply.
  2. 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);
        });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search