如何使用 sweet alert ajax request 使用用户提供的输入更新内容?
ajax请求后数据没有更新。
代码
@import url('~@/styles/xxx.less');
edit_stock.php
<script>
function change_stock(item_id) {
swal({
title: "Edit Stock!!",
text: "Enter the stock No: you wanded to change",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
inputPlaceholder: "Write something"
}, function (inputValue) {
if (inputValue === false)
return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
setTimeout(function () {
$.ajax({
type: "POST",
url: "edit_stock.php",
data: {stock_no: inputValue, itemid: item_id},
success: function () {
swal({title: "Updated!", text: "Stock No: has Changed", type: "success", },
function () {
location.reload(true);
});
}
});
}, 2000);
});
}
</script>
答案 0 :(得分:0)
尝试:
$.ajax({
type: "POST",
url: "edit_stock.php",
data: {stock_no: inputValue, itemid: item_id},
success: function () {
swal({title: "Updated!", text: "Stock No: has Changed", type: "success" }).then(function() {
location.reload(true);
});
});
});