Home > Software engineering >  ajax works locally fine but not on server laravel 8
ajax works locally fine but not on server laravel 8

Time:07-29

I'm beginner on ajax with laravel. I want to post update with ajax. I implement ajax that works fine on local machine but when i upload on server it not working. I'm tired to solve this problem.

Hearder:

<meta name="csrf-token" content="{{ csrf_token() }}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

body:

<script type='text/javascript'>
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');                           

$(document).on("click", ".update42" , function() {
var edit_id = 42;
var name = 1   1;
    $.ajax({
    url: '/dashboard/post/42',
    type: 'patch',
    data: {_token: CSRF_TOKEN,id: edit_id,download_count: name},
    success: function(response){
        alert(response);
    }
                                                });                                          
}); 
</script>

CodePudding user response:

Just full address then solve

url: 'https:/yoursite.com/dashboard/post/42',

CodePudding user response:

Add this to your script

    var WebURL = {!! json_encode(url('/')) !!}

then use it in your AJAX url

url: WebURL   '/dashboard/post/42',
  • Related