admin管理员组文章数量:1022405
This might be a duplicate, but I couldn't find an answer. I have a button which is making an ajax call and doing the functionality on click. But I need to restrict that by giving a confirmation pop up "Are you sure to delete this account?" with "Yes", "No" options. Im using a single button to delete/add accounts, so the text on confirmation dialogue should change accordingly.
<button type="submit" id="StatusChange" name="StatusChange" class="btn btn-primary pull-right">
"Click to Delete Account"
</button>
$("#StatusChange").click(function () {
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data){
location.reload();
}
});
});
Thanks!
This might be a duplicate, but I couldn't find an answer. I have a button which is making an ajax call and doing the functionality on click. But I need to restrict that by giving a confirmation pop up "Are you sure to delete this account?" with "Yes", "No" options. Im using a single button to delete/add accounts, so the text on confirmation dialogue should change accordingly.
<button type="submit" id="StatusChange" name="StatusChange" class="btn btn-primary pull-right">
"Click to Delete Account"
</button>
$("#StatusChange").click(function () {
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data){
location.reload();
}
});
});
Thanks!
Share Improve this question edited Sep 5, 2017 at 20:33 Pradvaar cruz asked Sep 5, 2017 at 19:35 Pradvaar cruzPradvaar cruz 2911 gold badge9 silver badges24 bronze badges 1- Possible duplicate of Intercepting a jQuery.ajax() call with confirm() – showdev Commented Sep 5, 2017 at 20:05
4 Answers
Reset to default 3$("#StatusChange").click(function () {
var x=confirm( "Are you sure you want to delete?!");
if(x){
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data)
{
location.reload();
}
});
}
});
Sample:
$("#StatusChange").click(function () {
var num=$("#Num").val();
var x=confirm( num==1?"Are you sure you want to delete?!":"Are you sure you want to Update?!");
if(x){
if(num==1)
$("div").remove();
else
$("div").text("test Update");
}
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="Num" type="number" value="1"/>
<input type="button" id="StatusChange" value="delete"/>
<br>
<div>Test</div>
Use standard javascript confirm dialog, like this:
$("#StatusChange").click(function () {
var result = confirm("Want to delete?");
if (result) {
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data){location.reload();}
});
}
});
You can read more here.
Like so:
$("#StatusChange").click(function () {
if(confirm("Are you sure you wish to continue?")){
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data)
{
location.reload();
}
});
}
});
$("#StatusChange").click(function() {
var state = 'ACTIVE';
var id = '12345';
if (confirm("Are you sure to delete this account?")) {
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: {
currentStatus: state,
accountId: id
},
success: function(data) {
location.reload();
}
});
} // can optionally add an else statement here if user cancelled
});
This might be a duplicate, but I couldn't find an answer. I have a button which is making an ajax call and doing the functionality on click. But I need to restrict that by giving a confirmation pop up "Are you sure to delete this account?" with "Yes", "No" options. Im using a single button to delete/add accounts, so the text on confirmation dialogue should change accordingly.
<button type="submit" id="StatusChange" name="StatusChange" class="btn btn-primary pull-right">
"Click to Delete Account"
</button>
$("#StatusChange").click(function () {
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data){
location.reload();
}
});
});
Thanks!
This might be a duplicate, but I couldn't find an answer. I have a button which is making an ajax call and doing the functionality on click. But I need to restrict that by giving a confirmation pop up "Are you sure to delete this account?" with "Yes", "No" options. Im using a single button to delete/add accounts, so the text on confirmation dialogue should change accordingly.
<button type="submit" id="StatusChange" name="StatusChange" class="btn btn-primary pull-right">
"Click to Delete Account"
</button>
$("#StatusChange").click(function () {
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data){
location.reload();
}
});
});
Thanks!
Share Improve this question edited Sep 5, 2017 at 20:33 Pradvaar cruz asked Sep 5, 2017 at 19:35 Pradvaar cruzPradvaar cruz 2911 gold badge9 silver badges24 bronze badges 1- Possible duplicate of Intercepting a jQuery.ajax() call with confirm() – showdev Commented Sep 5, 2017 at 20:05
4 Answers
Reset to default 3$("#StatusChange").click(function () {
var x=confirm( "Are you sure you want to delete?!");
if(x){
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data)
{
location.reload();
}
});
}
});
Sample:
$("#StatusChange").click(function () {
var num=$("#Num").val();
var x=confirm( num==1?"Are you sure you want to delete?!":"Are you sure you want to Update?!");
if(x){
if(num==1)
$("div").remove();
else
$("div").text("test Update");
}
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="Num" type="number" value="1"/>
<input type="button" id="StatusChange" value="delete"/>
<br>
<div>Test</div>
Use standard javascript confirm dialog, like this:
$("#StatusChange").click(function () {
var result = confirm("Want to delete?");
if (result) {
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data){location.reload();}
});
}
});
You can read more here.
Like so:
$("#StatusChange").click(function () {
if(confirm("Are you sure you wish to continue?")){
var state = 'ACTIVE';
var id = '12345';
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: { currentStatus: state, accountId:id },
success: function(data)
{
location.reload();
}
});
}
});
$("#StatusChange").click(function() {
var state = 'ACTIVE';
var id = '12345';
if (confirm("Are you sure to delete this account?")) {
$.ajax({
type: "POST",
url: '@Url.Action("ChangeAccountStatus", "Account")',
data: {
currentStatus: state,
accountId: id
},
success: function(data) {
location.reload();
}
});
} // can optionally add an else statement here if user cancelled
});
本文标签: javascriptConfirmation dialogue on button click for jQueryStack Overflow
版权声明:本文标题:javascript - Confirmation dialogue on button click for jQuery - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745573066a2156852.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论