Retrieving JSON response from Backbone Save?

I am using a model to make a POST request to a webservice.
After a successfull POST request, I want to retrieve the JSON and use it for rendering in my view.

[
{
    "ModifiedOn": "2015-04-08 11:17:28.0",
    "BuildingCode": "AU1010A1",
    "BuildingName": "REGUS - BRISBANE",
    "ActionRequired": "A"
},
{
    "ModifiedOn": "2015-04-08 11:17:28.0",
    "BuildingCode": "BR1044A1",
    "BuildingName": "RIO SUL - RIO DE JANEIRO",
    "ActionRequired": "A"
},
{
    "ModifiedOn": "2015-04-08 11:17:28.0",
    "BuildingCode": "CN1018A1",
    "BuildingName": "Kings Landing",
    "ActionRequired": "A"
}]

The problem is that the JSON is flat, and when I try and look for it in the model.attributes all I can see is the request JSON.

So I tried modifying the save function to pass back the JSON but I have had no success.

            this.model.set({ "lastRefreshedDateTime": "2015-04-01T08:18:06.000+00:00", "ein": "" }); //needs to be refactored
        //send POST request to MTL backend which then forwards to EAS 
        this.model.save(null, {
            success: function (model, response)
            {
                model.locations = response;
                //console.log(response); // can see the response here, but how do I pass it back?

            },
            error: function (model, response)
            {
                console.log("error");
            }
        });

        console.log(this.model.locations); //is null, 

Is there a specific attribute name I can get for the response?

When I tried printing the attribute object there was no named variables.


Source: json

Leave a Reply