2 回答

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
為了顯示進(jìn)度,您可以設(shè)置檢查進(jìn)程狀態(tài)的時(shí)間間隔。如下所示:
<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貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊
我用這種方式解決了這個(gè)問(wèn)題:
<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 關(guān)注
- 159 瀏覽
添加回答
舉報(bào)