Advertisement
badlogic

AJAX GETTING AN API ONLINE

Nov 24th, 2016
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  window.setInterval(function(){//get the data every 1 sec
  2.     $.ajax({ // ajax call the json data
  3.       type:'GET',
  4.       url: 'https://jsonplaceholder.typicode.com/albums',
  5.       contentType: "application/json; charset=utf-8",
  6.       success: function (data) {
  7.  
  8.         for (var key in data) {//eto yung nag loloop ng data na nakuha online yan yung exact formating
  9.             if (data.hasOwnProperty(key)) {
  10.             console.log(key + " -> " + data[key].title);
  11.             }
  12.         }
  13.  
  14.         console.log(data);
  15.         //document.write(data);
  16.       },
  17.       dataType: 'json'
  18.     });
  19.  
  20.       }, 1000);
  21.  
  22.  
  23.  
  24.  
  25. //another ajax code
  26.  
  27. function preRequisitesSubjects()
  28.     {
  29.         $.ajax({
  30.             url: "registrar.php?",
  31.             type: "GET",
  32.             data:  {
  33.                 statpos: 'course_curriculum',
  34.                 action: 'prerequisites',
  35.                 cc_id: <?=$_GET['cc_id']?>,
  36.                 ccch_id: <?=$_GET['ccch_id']?>,
  37.                 ajax_prerequisites: '1'
  38.             },
  39.             success: function(data){
  40.  
  41.                 data.forEach(function(data){
  42.                     console.log(data);
  43.                     document.getElementById("e1").innerHTML +=
  44.                         "<option value="
  45.                         +data.ccc_id
  46.                         +">"
  47.                         +data.subjname_shortname
  48.                         +" - "
  49.                         +data.subjname_name
  50.                         +" </option>";
  51.  
  52.                 });
  53.  
  54.             },
  55.             dataType: 'json'
  56.         });
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement