Skip to content

Instantly share code, notes, and snippets.

@daehwann
Last active June 9, 2016 06:10
Show Gist options
  • Select an option

  • Save daehwann/77fbe54f9dbfd279ae1bdfa3d59aeba9 to your computer and use it in GitHub Desktop.

Select an option

Save daehwann/77fbe54f9dbfd279ae1bdfa3d59aeba9 to your computer and use it in GitHub Desktop.
Ajax progress check by using interval
var intervalObj = {
id: 0,
start: function (){
var inprogress = $(".inprogress").text("Wait");
var intervalId = 0;
intervalId = setInterval(function(){
var text = inprogress.text();
if (text.length < 50) {
inprogress.text(text + ".");
} else {
inprogress.text("Wait");
}
}, 50);
this.id = intervalId;
},
end: function () {
clearInterval(this.id);
$(".inprogress").text("");
}
};
intervalObj.start();
$.post("${resource.path}.json", data, function(data){
if (!data.error) { //success
$(".copy_form input").val('');
console.log(data);
} else { //error
alert(data.error);
}
//finish progress
intervalObj.end();
}, "json");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment