[Answered ]-Django: Why is my jQuery POST url changing when it hits the server?

2👍

✅

You’re sending the url as part of the form data. I believe it should be:

$.post(url, {vote:'test'})

Actually, the entire format you’re using is better for $.ajax, so maybe it might just be better to change that post to ajax and add a type: ‘POST’ like

    $.ajax({                                                                    
        url: url,
        type: 'POST',                                                              
        // TODO: implement this better.                                         
        data: {vote: 'test'},                                                   
        dataType: 'json',                                                       
        success: function() {                                                   
            myElement.toggleClass('arrow-selected');                            
            spinner.addClass('hidden');                                         
            myElement.removeClass('hidden');                                    
        },                                                                      
        error: function() {                                                     
            spinner.addClass('hidden');                                         
            myElement.removeClass('hidden');                                    
            // TODO: make this link to the signup modal.                        
            alert('You must be logged in to vote');                             
        }                                                                       
    });      

0👍

You are updating url in code

Check line var url = myElement.data('url');

Leave a comment