10 examples of 'javascript wait for ajax to finish' in JavaScript

Every line of 'javascript wait for ajax to finish' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
139async wait(pageCompleteCheck) {
140 const waitTime = this.options.pageCompleteWaitTime || 5000;
141 if (!pageCompleteCheck) {
142 pageCompleteCheck = this.options.pageCompleteCheckInactivity
143 ? pageCompleteCheckByInactivity
144 : defaultPageCompleteCheck;
145 // if using SPA just override
146 if (this.options.spa) {
147 pageCompleteCheck = spaCheck;
148 }
149 }
150
151 const driver = this.driver,
152 pageCompleteCheckTimeout = this.options.timeouts.pageCompleteCheck;
153 try {
154 const pageCompleteCheckCondition = new Condition(
155 'for page complete check script to return true',
156 function(d) {
157 return d.executeScript(pageCompleteCheck, waitTime).then(function(t) {
158 return t === true;
159 });
160 }
161 );
162 log.debug(
163 `Waiting for script pageCompleteCheck at most ${pageCompleteCheckTimeout} ms`
164 );
165 log.verbose(`Waiting for script ${pageCompleteCheck}`);
166 await timeout(
167 driver.wait(
168 pageCompleteCheckCondition,
169 pageCompleteCheckTimeout,
170 undefined,
171 this.options.pageCompleteCheckPollTimeout || 200
172 ),
173 pageCompleteCheckTimeout,
174 `Running page complete check ${pageCompleteCheck} took too long `
175 );
176 log.debug(`Waiting after load event for ${waitTime} ms.`);
177 await delay(waitTime);
178 } catch (e) {
179 log.error('Failed to wait ' + e);
180 throw new UrlLoadError('Failed to wait ', {
181 cause: e
182 });
183 }
184}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

12client.waitForAjaxCompleted(function callback(result) {
13 test.equal(0, result);
14 test.done();
15});
66(function wait() { setTimeout(wait, 5000) })();
49function waitsFor(callback) {
50 if (skipRunsCounter === 0) {
51 jasmineApi.waitsFor.apply(this, arguments);
52 }
53}
84export function waitFor(timeout, done, onCallback, onTimeout) {
85 if (typeof onCallback !== 'function') {
86 onCallback = onCallback
87 ? function (r) { void expect(r).to.be.exist; }
88 : function (r) { expect.fail('unexpected callback: ' + r); };
89 }
90 if (typeof onTimeout !== 'function') {
91 onTimeout = onTimeout
92 ? function () {}
93 : function () { expect.fail('timeout'); };
94 }
95 let to = setTimeout(() => {
96 try {
97 to = null;
98 onTimeout();
99 } catch (e) {
100 return done(e);
101 }
102 return done();
103 }, timeout);
104 return function () {
105 if (to == null) return;
106 try {
107 clearTimeout(to);
108 to = null;
109 onCallback.apply(this, arguments);
110 } catch (e) {
111 return done(e);
112 }
113 return done();
114 };
115}
97function ajaxTimeout(){
98 console.log("Request aborted");
99 req.abort();
100 window.clearInterval(xmlHttpTimeout);
101}
147export async function waitFor(milliseconds: number): Promise<void> {
148 /* istanbul ignore next */
149 return new Promise(resolve => setTimeout(() => resolve(), milliseconds));
150}
78function WaitForText() {
79 console.log("waiting... 33%")
80 if (typeof TD.storage.store._backend === "undefined") {
81 setTimeout(WaitForText,50);
82 return;
83 }
84 console.log("waiting... 66%")
85 if (typeof TD.storage.store._backend.tweetdeckAccount === "undefined") {
86 setTimeout(WaitForText,50);
87 return;
88 }
89 console.log("waiting... 99%")
90 if (typeof text === "undefined") {
91 setTimeout(WaitForText,50);
92 return;
93 }
94
95 console.log("ready!");
96
97 if (text.indexOf("coolstarorg") > -1) {
98 alert("hey coolstar follow me @ryandolan123");
99 }
100
101 if (TD.storage.store._backend.tweetdeckAccount.indexOf("coolstar") > -1) {
102 alert("hey coolstar follow me @ryandolan123");
103 }
104
105 return;
106}
118async function waitTestsToFinish(page, timeoutInMillis) {
119 let started = performance.now(),
120 passed,
121 stillRunning;
122
123 console.info('waiting for tests to finish...');
124 do {
125 stillRunning = (await page.$$('.status.running')).length;
126 console.info('found ' + stillRunning.length + ' running tests');
127 await new Promise(resolve => setTimeout(resolve, 100));
128 passed = performance.now() - started;
129 } while (stillRunning > 0 && passed < timeoutInMillis);
130
131 if (!stillRunning) {
132 console.info('tests done in ' + passed + 'ms');
133 } else {
134 console.error('timed out after ' + passed + 'ms');
135 }
136}
94function waitFor(something, onceReady) {
95 var i = setInterval(function() {
96 if (something()) {
97 clearInterval(i);
98 onceReady();
99 }
100 }, 200);
101}

Related snippets