[Fixed]-A element not posting with AJAX

1👍

You have to prevent the default action of the anchor, which will just reload the page when the href attribute is empty

$(document).ready(function(){
    $('#post').on('click', function(e) {

        e.preventDefault(); 

        $.ajax({
            type : 'POST',
            url  : window.location.href,
            data : {csrfmiddlewaretoken: '{{ csrf_token }}' },
            dataType: 'json',
            success: function(data){
                console.log(data);
            }
        });
    });
});
👤adeneo

Leave a comment