Last active
June 9, 2016 06:10
-
-
Save daehwann/77fbe54f9dbfd279ae1bdfa3d59aeba9 to your computer and use it in GitHub Desktop.
Ajax progress check by using interval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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