How all,
I created a button inside of a modal header that when clicked, should log you off. However, that is not happening. When I click the button, the page reloads again with the modal appearing. Does anyone know what could be causing this?
This is how I have my modal set up. Inside modal-header, I added the code so that when the user clicks on "x", it should sign them off.
<div id="myModal2" class="modal fade" role="dialog" data-keyboard="false" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content" style="text-align:center">
<div class="modal-header">
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "formlogoff" }))
{
<span name="requestVerificationToken">@Html.AntiForgeryToken()</span>
<button id="signoff" class="close">x</button>
}
</div>
<div class="modal-body">
<div>
<p>After the free trial you will automatically started your paid monthly subscriptio</p>
</div>
<input type="checkbox" name="ThirtyTrial" id="ThirtyTrial" class="filled-in chk-col-deep-orange" required>
<label for="ThirtyTrial">Please do not show this to me again.</label>
</div>
<div class="modal-footer" style="text-align:center">
<a class="modal-free-trial" onclick="createModal('@Url.Action("AddCustomer", "Billing")')">Add Payment</a>
</div>
</div>
</div>
</div>
This is my Ajax call for signing off
$('#signoff').on('click', function (event) {
event.preventDefault()
var form = $('#formlogoff');
var token = $('input[name="__RequestVerificationToken"]', form).val();
$.ajax({
url: '/Account/LogOff',
data: { __RequestVerificationToken: token },
type: "POST",
success: function (data) { window.location.href = '/Account/Login' }
});
});
At the end of your click
callback, can you try return false;
eg
$('#signoff').on('click', function (event) {
event.preventDefault()
// ...
$.ajax({
// ...
});
return false;
});
我从签收函数中删除了 event.preventDefault()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.