pjldesign
pjldesign

Reputation: 397

Pull different data strings from JSON via Ajax

My client has a jobs board whose API data I'm pulling via Ajax. I can parse the "jobs" data but cannot seem to pull any thing else. For instance, this works to pull the names of job listings to a select box:

$.ajax({
    url:'https://api.greenhouse.io/v1/boards/roivantsciences/jobs/',
    type:'GET',
    data: 'q=' + "",
    dataType: 'json',
    success: function( json ) {
        $.each(json.jobs, function(i, value) {
            $('#myselect').append($('<option>').text(value.title).attr('value', value.title));
        });
    }
});

But when I change "json.jobs" to anything else like "json.offices" or "json.locations" nothing is pulled. How do I go about accurately targeting these data strings to cull together for a complete careers page? Appreciate any guidance whatsoever thanks.

This is the JSON if you need to take a look:

https://api.greenhouse.io/v1/boards/roivantsciences/jobs/

Upvotes: 1

Views: 67

Answers (2)

user8232179
user8232179

Reputation:

Ive done a small test:

$.ajax({
url:'https://api.greenhouse.io/v1/boards/roivantsciences/jobs/',
type:'GET',
data: 'q=' + "",
dataType: 'json',
success: function( json ) {
   console.log(json)
}

});

What I got back from console is that your json object only has 'jobs' as the top attribute in it.

You have to go through it like this to get locations:

 $.each(json.jobs, function(i, value) {
        console.log(value.location);
    });

then you have the location object inside this you got the attribute 'name'

so u can get the names with value.location.name

Upvotes: 0

Srinivas ML
Srinivas ML

Reputation: 730

try pull location.name for all jobs $.each(json.jobs, function(i, value) { $('#myselect').append($('<option>').text(value.location.name).att‌​r('value', value.location.name)); });

Upvotes: 1

Related Questions