octal
2 months ago

Ajax queries with https

Posted 2 months ago by octal

Hello, I have a laravel website, and I have some ajax queries in some screens. When I call those queries directly in the browser or via ajax it works. I'm passing the website to https. Everything seems to work, and even those queries pass when I call them via the browser directly, but when called in ajax, I have a server error (500) .

Do you have any idea????

The minimum code that reproduce my problem is:

 $("#refreshmsglist").click(function(e)
        {
            $('#btngetmessages > i ').addClass('spinner');
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': '<?php echo csrf_token(); ?>'
                }
            });
            $.ajax({
                method: 'GET',
                url: '/trackers/{{ $tracker->id  }}/messages',
                data: {}, // a JSON object to send back
                
                success: function(response){ 
                    console.log(response);
                    document.location.reload(true);
                },
                error: function(jqXHR, textStatus, errorThrown) { 
                    console.log(JSON.stringify(jqXHR));
                    console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
                    $('#btngetmessages > i ').removeClass('spinner');
                },

                complete: function () {
                    $('#btngetmessages > i ').removeClass('spinner');
                }
            });
        });

on my brower if I put https://www.mywebsite.com/trackers/56/messages I got the messages of the tracker id 56. When using ajax it doesn't work (it was working ok on HTTP website, it doesnt work for HTTPS).

I'm passing correctly the X-CSRF-TOKEN. Is there something I'm missing with the headers to satisfy Laravel when using https?

Since I'm using Auth() engine provided by default by Laravel, I added

xhrFields: {
                     withCredentials: true
                },

But this doesn't change anything the error I'm getting is:

Request URL: https://www.mywebsite.com/trackers/57/messages
Request Method: GET
Status Code: 500 
Remote Address: 109.234.164.13:443
Referrer Policy: no-referrer-when-downgrade

Please sign in or create an account to participate in this conversation.