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

JS - Add property to JSON if query string exist in URL

0 votes
7 views
added Jul 6 in Javascript by LC Marshal Lieutenant (13,570 points)
edited Jul 12 by LC Marshal
//example URL: http://localhost:8080/?uid=1&nid=18&act=fund#/
//example URL: http://localhost:8080/?uid=1&nid=12&act=buy#/
(async () => {
  function getUrlParam() {
      let params = {};
      let parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
          params[key] = value;
      });
      return params;
  }

  let status = null,
      actParam = getUrlParam()['act'];   

  if(actParam == 'buy#/') {
    status = 1;
  } else if(actParam == 'fund#/') {
    status = 2;
  }

  let apiUrl = `${mainSiteUrl}/api/property-units.json?property_nid=${this.pid}`;
  if(status) apiUrl += `&status=${status}`;

  const { data } = await this.axios.get(apiUrl);
  this.setListOfUnits(data);
})

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.
...