Reputation: 1763
I use Bootstrap in my application. After adding some design I started adding some functionality. I have a navbar with a dropdown, like here. On my Website, this also features a logout link:
<li><a href="/logout">Logout</a></li>
But my problem is, that my logout will only accept POST requests. So my simple question is: How can I make this a POST request instead of GET?
Thanks
Upvotes: 2
Views: 3670
Reputation: 18891
Use
<li><a href="/logout">Logout</a><form method="post" action="logout.php"><!--Whatever must be in your form--></form></li>
and
$("a + form").click(function(){
$(this).next('form').submit();
});
Upvotes: 2
Reputation: 43479
There is two ways to get it solved:
Change your PHP side so it accepts $_GET
request. (Tip: Use $_REQUEST
to get value from $_GET
or $_POST
.
Use jQuery/js for that (sorry, no js example).
<a href="/logout" id="logout">Logout</a> // load jQuery first. $(document).ready(function(){ $("#logout").click(function(){ $.post($(this).attr("href"), function(){ window.location = "www.example.com/login"; // or any other page after logging out. }); }); });
Upvotes: 3
Reputation: 2147
If you want POST request then you should use form
Example:
<form method='post' action='logout.php'>
<input type='submit' value='Logout'>
</form>
Upvotes: 1