0
今はsetIntervalを使用していますが、setTimeoutを使用します。 //機能関数をsetTimeoutに変換する方法
$.when(
data['layout'] = "getMessages",
data['limit'] = limit,
fetchMsg(data,'[data-messages]',{"background-color":"#fff"})
).then(
setInterval(function(){
data['lastupdate'] = localStorage.lastupdate;
data['layout'] = "getNewMessages",
fetchMsg(data, '[data-body-new]',{"background-color":"#b4eeb4"});
}, 1000)
);
function fetchMsg(info, container, messageStyle){
$.ajax({
method: "POST",
url: window.root+"/index.php",
"data": info,
error: function() {
alert('error');
},
success: function(result) {
..........
}
});
私は以下しようとしたが、それは動作しません:
setTimeout(function(){
data['lastupdate'] = localStorage.lastupdate;
data['layout'] = "getNewMessages",
fetchMsg(data, '[data-body-new]',{"background-color":"#b4eeb4"});
}, 1000)
// 機能
function fetchMsg(info, container, messageStyle){
$.ajax({
method: "POST",
url: window.root+"/index.php",
"data": info,
error: function() {
alert('error');
},
success: function(result) {
..........
},
complete:fetchMsg
});
コードの内容を簡単に説明できますか? "[私は] setTimeoutを使いたいと思っています。もう少し文脈が私たちがあなたを助けるのに役立ちます。 – nnnnnn
壊れたコードは、そのコードが何をすることが期待されているかについての適切な説明の代わりには適していません – charlietfl
@nnnnnn setTimeoutはx秒後に1回要求を出し、setIntervalはx秒の間隔で行います。ページをリロードするときにエラーを警告します。 – 112233