Michael Kohler
Michael Kohler

Reputation: 753

Ruby / Sinatra - POST data without form

I have a button which is a link. When a user clicks on that link, I want to do a POST to another route which processes this click. Can I do it somehow without using a <form>? That means, just clicking on the link and the link is not the submit button of a form.

<a href="/buyitem/"><button class="btn btn-info small">Buy Item</button></a>

I know that it would be possible with AJAX, but I wonder if there is another way.

AJAX-way:

$.post('/buyitem', { key1: 'value1', key2: 'value2' }, function(result) {
    alert('successfully posted key1=value1&key2=value2');
});

Upvotes: 1

Views: 564

Answers (1)

three
three

Reputation: 8478

no, there's no way of telling an html link without js to got down the post route. Tried to figure out the same for DELETE links.

Upvotes: 1

Related Questions