Skip to main content
2 of 2
replaced http://sharepoint.stackexchange.com/ with https://sharepoint.stackexchange.com/

You are in the right path. Use the search REST API. The below code from this post should get you started.

    <button id='btnGetSites'>Get Sites</button>

<div id='list'>

</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<script type='text/javascript'>


(function(){
    var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
    var url = siteUrl + "/_api/search/query?querytext='(contentclass:STS_Site OR contentclass:STS_Web)'";
    $('#btnGetSites').click(function(){
        console.log('start..');

        $.ajax({
            method: 'GET',
            url: url,
            dataType: 'json',
            success: success,
            error: error
        });

        function success(data){
            var html = '';

            $.each(data.PrimaryQueryResult.RelevantResults.Table.Rows, function(index, row){                
                var title = '';
                var url = '';
                $.each(row.Cells, function(i, obj){             
                    if(obj.Key === 'Title'){
                        html += obj.Value; 
                    }
                    else if(obj.Key === 'Path'){
                        html += ": " + obj.Value + "<br/>";
                    }               
                });         
            });

            $('#list').append(html);
        }
        function error(err){
            console.log(err);
        }       
        return false;
    });

}());

</script>