[英]AJAX not working in JQUERY confirm dialogue
我试图在用户确认JQUERY确认对话框后调用ajax函数。 但是放入确认部分之后。 它给我一个错误,并且不起作用。 请注意,当放在确认对话框之外时,ajax功能可以正常工作。
我的代码是
function approveApp(intAppId) {
$.confirm({
title: 'Are you sure you want to approve this application?',
content: '',
buttons: {
confirm: function () {
var test = intAppId;
alert(test) //This alerts the word 'Undefined'
var intAppId = intAppId;
$.ajax({
url: 'adminreport.aspx/approveApp',
type: 'POST',
data: JSON.stringify({ intAppId: intAppId }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data.d) {
alert("It worked!");
}
}
});
},
cancel: function () {
}
}
}
});
}
您正在将参数作为intAppId
传递给外部函数。
但是,您还要在内部函数中声明该变量,并使用它(大概)保留外部参数:
var intAppId = intAppId;
此重新声明隐藏了外部变量。 您可以将其完全删除,并在ajax调用中使用参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.