skip to Main Content

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>

2

Answers


  1. Chosen as BEST ANSWER

    Just full address then solve

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

  2. Add this to your script

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

    then use it in your AJAX url

    url: WebURL + '/dashboard/post/42',
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search