10 examples of 'get data from url' in JavaScript

Every line of 'get data from url' 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
15function get_data(url){
16
17 dir = url.split('/');
18 console.log("URL : "+ url);
19 var data = undefined;
20
21 for(var i in dir){
22 data = ds[dir[i]];
23 if(data == undefined) break;
24 }
25
26 return data;
27}
34getURLData(url) {
35 return this.urlPages[url];
36}
40function getData(url) {
41 // the async call is 'hidden' in this function
42 request(url, (err, res, body) => {
43 if (err) it.throw(new Error('invalid API call'))
44 it.next(body)
45 })
46 // the function does not return anything
47}
84function _getData(url) {
85 return new Promise((resolve, reject) => {
86 request(url, (error, response, body) => {
87 error && reject(error);
88 body && resolve(body);
89 })
90 })
91}
188function getData (url, callback) {
189 $.ajax({
190 url: url,
191 headers: {
192 Authorization: 'token ' + tableau.password
193 },
194 success: function(result, textStatus, jqXHR) {
195 var link = jqXHR.getResponseHeader('link'),
196 next = getNextPage(link);
197
198 // GET queries return an array of results.
199 if (util.isArray(result)) {
200 data = result;
201 }
202 // SEARCH queries return an object with an array of results in "items".
203 else if (typeof result === 'object' && util.isArray(result.items)) {
204 data = result.items;
205 } else {
206 throw 'Unexpected result set, please check your API call syntax.'
207 }
208
209 callback(data, next);
210 },
211 error: function (jqXHR, textStatus, error) {
212 throw 'Invalid API call: ' + url + '\n Please check your syntax. Error:' + error;
213 }
214 });
215}
26export function getData (url: string, config?: RequestInit): Promise {
27 return request('GET', url, config)
28}
8function Get(url){
9 var Httpreq = new XMLHttpRequest(); // a new request
10 Httpreq.open("GET",url,false);
11 Httpreq.send(null);
12 return Httpreq.responseText;
13}
229function getData(url, callback, tries){
230 options.path = url;
231 var conn = getHttp().get(options, function(res){
232 var chunks = '';
233 res.on('data', function(chunk) {
234 chunks += chunk;
235 });
236 res.on('end', function () {
237 var parsed = {};
238
239 if (!chunks && (!tries || tries < 3)) {
240 return getData(url, callback, (tries||0)+1);
241 }
242
243 // Try-Catch added by Mikael Aspehed
244 try{
245 parsed = JSON.parse(chunks);
246 }catch(e){
247 parsed = {error:e};
248 }
249
250 return callback(null,parsed);
251 });
252
253 res.on('error', function(err){
254 return callback(err, null);
255 });
256 });
257
258 conn.on('error', function(err){
259 return callback(err, null);
260 });
261}
31export async function getData (sourceUrl, params = {}) {
32 const url = new URL(sourceUrl)
33 const mergedParams = { ...params, access_token: config.token }
34
35 Object.keys(mergedParams).forEach(key => url.searchParams.append(key, mergedParams[key]))
36
37 const result = await window.fetch(url.toString())
38 const json = await result.json()
39
40 return json
41}
186getURL(url, callback) {
187 this.dbConn.get('usafe', url, (obj) => {
188 if (!obj || obj === 'undefined') {
189 callback([]);
190 } else {
191 // The type check is being done, to ensure,
192 // when users upgrade from 7.x to 8.0.x it does not break.
193 // The reason it might break is because the usafe
194 // was stored as JSON in 7.x and as string in 8.x.
195
196
197 let record = null;
198 if (typeof (obj) === 'string') {
199 record = JSON.parse(obj);
200 } else {
201 record = obj;
202 }
203 callback([record]);
204 }
205 });
206}

Related snippets