Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function get_data(url) {
  2.     var xhr = new XMLHttpRequest();
  3.     xhr.open('GET', url, true);
  4.     try {
  5.         xhr.setRequestHeader('X-XSRF-TOKEN', 'iYQml0FRdtzo5gnIIZOur59/HjaKG0azoODhOpKLXt9uZxAB+ixTqXA2tBHU7MNofgpmFG2OdtyWTnMoCr3PJg==');
  6.     } catch (e) {};
  7.     try {
  8.         xhr.setRequestHeader('Accept-Language', 'en-us');
  9.     } catch (e) {};
  10.     try {
  11.         xhr.setRequestHeader('Accept', 'application/json, text/plain, */*');
  12.     } catch (e) {};
  13.     xhr.withCredentials = true;
  14.     xhr.onerror = function(e) {
  15.        
  16.     };
  17.     xhr.onload = function(e) {
  18.      
  19.       load_data(url,xhr.responseText)
  20.     }
  21.     xhr.send('');
  22. }
  23.  
  24. function load_data(url, response) {
  25.     $.post( "url_send", { content: response, url: url })
  26.                       .done(function( data_andwer ) {
  27.                        
  28.                       });
  29.     var jsonResponse = JSON.parse(response);
  30.      
  31.       if(url.indexOf('SystemGroups')>0) {
  32.        console.log(url);
  33.       }else if(url.indexOf('subcategories')>0) {
  34.           for (data in jsonResponse.systemGroups) {
  35.              var systemGroups = jsonResponse.systemGroups[data];
  36.              url = 'https://epc.teslamotors.com/api/SystemGroups/'+systemGroups['id']+'?vin=';
  37.              get_data(url);
  38.            
  39.         }
  40.  
  41.       }else if(url.indexOf('Categories')>0) {
  42.         for (data in jsonResponse) {
  43.             var subcat = jsonResponse[data]['subcategories'];
  44.             for (sub_data in subcat) {
  45.                 url = 'https://epc.teslamotors.com/api/Categories/24/subcategories/'+subcat[sub_data]['id'];
  46.                 get_data(url);
  47.  
  48.             }
  49.            
  50.         }
  51.  
  52.       }
  53. }
  54. get_data('https://epc.teslamotors.com/api/model3/Categories');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement