单击此按钮后如何创建确认框(模式弹出窗口):
<button id="sellButton" onclick="sendRequest(@item.Id)">Sell</button>
HERE POPUP MODAL(是/否)
当用户确认时,这应该发生
<script>
function sendRequest(id)
{
var request =
{
"itemId": id
};
$.ajax({
url: '/It/Sell',
data: JSON.stringify(request),
type: 'POST',
dataType: "html",
contentType: 'application/json; charset=utf-8',
error: function (err) {
alert('Error: ' + err.statusText);
},
success: function (result) {
$('#Table').html(result);
},
async: true,
processData: false
});
};
</script>
答案 0 :(得分:2)
if(confirm('are you sure?')){
var request =
{
"itemId": id
};
$.ajax({
url: '/It/Sell',
data: JSON.stringify(request),
type: 'POST',
dataType: "html",
contentType: 'application/json; charset=utf-8',
error: function (err) {
alert('Error: ' + err.statusText);
},
success: function (result) {
$('#Table').html(result);
},
async: true,
processData: false
});
}
答案 1 :(得分:0)
请看jquery.confirm。它应该能够解决你的问题。
答案 2 :(得分:0)
如果你想拥有一个简单实现的模态确认框,我会推荐 Bootstrap3对话
将必要的文件导入项目。并且
function sendRequest(id)
{
BootstrapDialog.confirm('Are you sure you want to continue?', function(result){
if(result) {
//Send Ajax Request
}
});
}