Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simulate POST on link/button click event

Have a list of editable items relative to a given user that I would like to be non-GET initiated; i.e. when clicking the edit button for a given entry, I would like that to initiate a POST to the target edit form screen.

How can I achieve this short of wrapping every edit button in the list in <form>...</form>?

Currently I have a jQuery location.href kicking the user to target edit screen; however, with GET the user could enter any id they like by simply entering a URI of their choosing.

$('.game-edit').click -> 
  location.href = '/admin/linescore/edit/' + getID($(this))

Can I click event POST a la location.href?

Ideas appreciated, thanks

like image 900
virtualeyes Avatar asked Jul 13 '26 03:07

virtualeyes


2 Answers

$('a').click(function(){
$('#formID').action = $(this).href
$('#formID').submit();
})
like image 107
Termis Avatar answered Jul 15 '26 18:07

Termis


Is there any reason you can't have jQuery do the POST for you? Given:

<a class="edit" href="...">Click Me</a>

...then:

$('a.edit').click(function(){
    var postUrl = $(this).attr('href');  // href attribute of clicked link
    $.post(.....); 
});

EDIT - Updated for clarity's sake

Cheers

like image 40
Madbreaks Avatar answered Jul 15 '26 16:07

Madbreaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!