10 examples of 'ajax wait for response' in JavaScript

Every line of 'ajax wait for response' 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
66(function wait() { setTimeout(wait, 5000) })();
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

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}
49function waitsFor(callback) {
50 if (skipRunsCounter === 0) {
51 jasmineApi.waitsFor.apply(this, arguments);
52 }
53}
12client.waitForAjaxCompleted(function callback(result) {
13 test.equal(0, result);
14 test.done();
15});
97function ajaxTimeout(){
98 console.log("Request aborted");
99 req.abort();
100 window.clearInterval(xmlHttpTimeout);
101}
145function ajaxGet(getURL, waitDialogText, onSuccess, modal)
146{
147 var fileId = null;
148 ajaxCall('GET', getURL, {}, waitDialogText, onSuccess, fileId, modal);
149}
147export async function waitFor(milliseconds: number): Promise<void> {
148 /* istanbul ignore next */
149 return new Promise(resolve => setTimeout(() => resolve(), milliseconds));
150}
52pollResponse(response, waitAllowed) {
53 if (this.closed) {
54 response.end(JSON.stringify({ id: this.id, close: true }));
55 }
56 else if (this.toSend.length > 0) {
57 response.end(JSON.stringify({ id: this.id, m: this.toSend }));
58 this.toSend = [];
59 }
60 else if (waitAllowed) {
61 if (this.response != null && this.response !== response) {
62 this.response.end(JSON.stringify({ id: this.id, old: true }));
63 this.response = null;
64 }
65 this.response = response;
66 return;
67 }
68 else {
69 response.end(JSON.stringify({ id: this.id }));
70 }
71 if (this.response === response) {
72 this.response = null;
73 this.reTimeout();
74 }
75}
66async function wait(ms) {
67 return new Promise(resolve => setTimeout(resolve, ms));
68}
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}

Related snippets