Storing data for a POST request in href - wrong practice?

I am writing a node.js application and am a little worried about how I create mail data to send to the server. For example, when I want to delete a data item, I put the identifier of the specified item in the href attribute:

<a class='delete' href="1231">Delete this data</a>
<!-- href is based on a variable I'm pulling from the server -->

When I click this link, I prevent the default actions and then run the ajax request:

//On click + ajax
body.on('click', '.delete', function(e){
e.preventDefault();
    $.ajax({
        type: 'POST',
        url: '/admin/report/detail/delete',
    data: {id: $(this).attr('href')},
    success: function(){
        //Success message
    },
    error: function(){
        //Error message
    }
});
});

I am wondering if it is bad practice to use the href attribute in this way? If so, what is the best way to store this data?

+5
source share
2 answers

. href , , ? , , .

<a class="delete" data-id="1231" href="#">

javascript:

...
data: { id: $(this).data('id') }
...

data: { id: $(this).attr('data-id') } 
+9

, , , . , , " " AJAX, ID.

- , , , ... ... , , .. , ?

+2

All Articles