2 回答
TA贡献1824条经验 获得超6个赞
为了显示进度,您可以设置检查进程状态的时间间隔。如下所示:
<script type="text/javascript">
function save() {
let ip = $('#ip').val();
let req = $.ajax({
type: 'POST',
url: 'xample.php',
data: {
ip: ip
}
});
req.done(function (res) {
//================================
// set interval for check status of progress every 1 sec
setInterval(() => {
let reqStatus = $.ajax({
type: 'POST',
url: 'xampleStatus.php',
data: {
ip: ip
}
});
req.done(function (resStatus) {
console.log(resStatus);
});
}, 1000);
//================================
if (res == "cant") {
console.log('fail');
} else
console.log('Start progress');
});
}
</script>
TA贡献1798条经验 获得超3个赞
我用这种方式解决了这个问题:
<script src="jquery.min.js"></script>
<script type="text/javascript">
function save() {
var ip = $('#ip').val();
var data = new FormData();
data.append('ip', ip);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'example.php', true);
xhr.send(data);
xhr.onreadystatechange = function () {
if (xhr.status === 200) {
if (xhr.readyState === XMLHttpRequest.LOADING) {
$('#loadarea').html(xhr.response);
}
if (xhr.readyState === XMLHttpRequest.DONE) {
$('#loadarea').append("finished!!!");
}
}
}
}
</script>
- 2 回答
- 0 关注
- 119 浏览
添加回答
举报