Fetch all features

HTML

<div id="console"></div>

JavaScript

var url = 'https://gis.baywest.com/proxy/proxy.ashx?https://gis.baywest.com/baywest/rest/services/JBA/SearchableLayers/MapServer/8';
$(function () {
    //onload, so the query for the count
    //where=1%3D1&returnIdsOnly=true&f=json&
    $.ajax(url + '/query', {
        data: {
            where: '1=1',
            returnIdsOnly: true,
            f: 'json'
        },
        dataType: 'jsonp',
        success: parseIds,
        error: function (jqXHR, status) {},
        complete: function (jqXHR, status) {}
    });
});
//array for our features
var featureSet  = [];
var totalBatches = 0;
function parseIds(data, status, jqXHR) {
    
     $('#console').append('Im hit');
    return;
    //break the id's into batches of 500, and make iterative requests
    //accumulating the features into an array
    var i, j, temparray, chunk = 200;
    totalBatches = Math.ceil(data.objectIds.length / chunk);
    $('#console').append('Queried Layer and got ' + data.objectIds.length + ' objectIds <br/> Will fetch in ' + totalBatches + ' batches of ' + chunk + '<br/>');
    for (i = 0, j = data.objectIds.length; i < j; i += chunk) {
        //$('#console').append(' sending chunk ' + i + ' <br/>');
        temparray = data.objectIds.slice(i, i + chunk);
        getFeatures(temparray);
    }
}

function getFeatures(objectIdArray){
    $.ajax(url + '/query',{
        data:{
            objectIds:objectIdArray.join(),
            outFields:'fire_name,start_date,start_hour,location,inc_type,cause,area_,area_meas',
            f:'json'
        },
        dataType:'jsonp',
        success: parseFeatures,
        error: function (jqXHR, status) {},
        complete: function (jqXHR, status) {}
    });
}
function parseFeatures(data,status,jxXHR){
     $('#console').append('  fetched set of features  ' + data.features.length + '<br>');
    //union the new features
    featureSet = _.union(featureSet, data.features);
    totalBatches -=1;
    $('#console').append(' Batches left: ' +...