Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

API - Get URL parameter with jQuery function

0 votes
12 views
added Jul 4 in API by LC Marshal Lieutenant (14,830 points)
edited Jul 13 by LC Marshal
$(function() { 
  //create function to get URL pramater
  function getUrlParameter(vali) {
      vali = vali.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
      var regex = new RegExp('[\\?&]' + vali + '=([^&#]*)');
      var results = regex.exec(location.search);
      return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
  };
       //fetch from api
  var propertyApi = 'https://cube.fundmyhome.com/api/property-units.json?property_nid=',
      //get URL parameter with getUrlParameter function
      nidValue =  getUrlParameter('nid'),
      //combine and produce final api source
      fullApiLink = propertyApi + nidValue;
      //to test the output
      console.log(fullApiLink);//example output https://cube.fundmyhome.com/api/property-units.json?property_nid=12

  $.ajax({
    url: fullApiLink,
    dataType: 'json',
    type: 'get',
    cache: 'false',
    success: function(data) {
      $(data["0"]).each(function(index, row) {
        var unitStatus = (data["0"].unit_status),
            statusLabel = $('#main_panel .listing-batch.hidden-sm.hidden-xs');

        if (unitStatus === '0' ) {
          // console.log('no status')
          $(statusLabel).html('Coming Soon');
        } else if (unitStatus === '1') {
          $(statusLabel).html('Unfunded');
        } else if (unitStatus === '2') {
          $(statusLabel).html('Buying Closed. Now Funding');
        } else if (unitStatus === '3') {
          $(statusLabel).html('Funded');
        } else if (unitStatus === '4') {
          $(statusLabel).html('Closed');
        }
      });
    }
  })
});

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...