I have an API for getting an array of objects that represent Boats and it returns an "id", "name", "length" and "harbour_id" for each boat.
I also have another API for getting the "harbour_name" from "harbour_id". While writing AJAX requests for both is not a problem, the thing that puzzles me is this: I have to construct an array of objects where every boat contains all the data for itsef, "harbour_name" included.
How do I do it?
Let's write some code:
var boats;
function getBoats() {
$.ajax({
url:'/',
type:'GET',
success: gotBoats,
error: didntGetBoats,
});
}
function gotBoats(data, textStatus, jqXHR) {
boats = $.parseJSON(data);
// I presume I need to make another request somewhere around here
// but I'm not sure how to do it to bind the response data to
// the correct boat
}
function didntGetBoats(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
After this problem is solved, I also need to be able to do it backwards - input a new boat and post it's location to a proper place and the rest of the data to it's proper place.
Thanks in advance for tips :)