我已经做了这个sweetalert但是我有一个问题,我想在输入中输入的密码(通过data.php文件中的php代码)保存到txt文件。表单有效(我能够插入密码)但插入的密码不会保存到txt文件中。
SWAL CODE:
swal({
title: 'Submit to confirm',
html:
'<input id="swal-input1" placeholder="Password" class="form-control mb-1" type="password">',
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: true,
buttonsStyling: false,
confirmButtonClass: 'btn btn-primary btn-lg',
cancelButtonClass: 'btn btn-lg',
preConfirm: function () {
return new Promise((resolve, reject) => {
resolve({
Password: $('input[placeholder="Password"]').val()
});
});
},
allowOutsideClick: false
}).then(function (result) {
$.ajax({
type:'GET',
data:Password,
url:'data.php',
success:function(data) {
alert(data);
}
});
}).catch(swal.noop)
PHP CODE(将输入值保存为txt文件) - &gt; data.php
<?php
$txt = "data.txt";
if (isset($_GET['swal-input1'])) {
$fh = fopen($txt, 'a');
$txt=$_GET['swal-input1'];
fwrite($fh,$txt); // Write information to the file
fclose($fh); // Close the file
}
?>
谢谢,希望你能帮帮我。
答案 0 :(得分:0)
这是修订版。
基本上更新了ajax请求的数据部分
data:{'swal-input1':$('input[placeholder="Password"]').val()},
完整代码
swal({
title: 'Submit to confirm',
html:
'<input id="swal-input1" placeholder="Password" class="form-control mb-1" type="password">',
showCancelButton: true,
confirmButtonText: 'Submit',
showLoaderOnConfirm: true,
buttonsStyling: false,
confirmButtonClass: 'btn btn-primary btn-lg',
cancelButtonClass: 'btn btn-lg',
preConfirm: function () {
return new Promise((resolve, reject) => {
resolve({
Password: $('input[placeholder="Password"]').val()
});
});
},
allowOutsideClick: false
}).then(function (result) {
$.ajax({
type:'GET',
data:{'swal-input1':$('input[placeholder="Password"]').val()},
url:'data.php',
success:function(data) {
alert(data);
}
});
}).catch(swal.noop)