Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Best way to handle an if/else statement when retrieving data

I'm using this code to retrieve data from a Sharepoint:

    $(function () {
    
    $.ajax({

        url: '/sites/site/_api/web/lists/getbytitle(\'Townhall\')/items?&$orderby=Modified desc',
        method: "GET",
        headers: {
            "Accept": "application/json;odata=verbose"    
        },
        success: function (data) {
            var latestTHResults = data.d.results;
            console.log(latestTHResults);
            readData(latestTHResults);
        },
        error: errorHandler()
    });

    function errorHandler() {
        console.log('error');
    }

    function readData(data) {
        var latestTHArray = []
        for (var i = 0; i < 2; i++) {

            latestTHArray.push(data[i]);
            render(latestTHArray[i]);

        }
    };

    function render(latestTHArray) {
        var latestTHTemplate = $("#latestTH-template").html();
        var latestTHList = latestTHArray
        $("#latestTH").append(Mustache.render(latestTHTemplate, latestTHList));
    };
});

In my HTML, for example, the field I am trying to retrieve is {{QA}} in the format of a URL:

<li><p>Q&As - </p><a href="{{QA}}" target="_blank">Download here</a></li>

What I need is for something like this:

<li><p>Q&As - </p>
    if {{QA}} = null
       display <p>Unavailable</p></li>
    else
       display <a href="{{QA}}" target="_blank">Download here</a></li>

Can this be done in HTML, new JS or the existing JS used to pull the data?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!