SomeGuy1989
SomeGuy1989

Reputation: 483

JQuery getJson callback not parsing json

I used to be pretty comfortable with using jquery for json, but I'm having an odd issue tonight that I just can't wrap my head around. JQuery sends the request, the server fills it properly, but then there's no way to pull the data out of the json response.

The server's ASP.MVC and serializing using the JsonResult/Json().

I'm completely baffled by this, thanks for any help you can give!

Here's my function:

function LoadAllPhotos(containerSelector, formSelector) {
  //var serial = "{ \"EntryDate\" : \"" + $(formSelector + " .EntryDate").val() + "\", \"OwnerId\": \"" + $(formSelector + " .OwnerId").val() + "\"}";
  var serial = $(formSelector).serializeArray();
  $.getJSON("/journal/json/allphoto", serial, function(data, transportStatus) {
    if (transportStatus == "success") {
      alert(data.Length);
      alert(eval(data).Length);
      for (var key in data) {
        alert(key);
      }
    } else {
      alert("Something bad happened, handle the error.");
    }
  });
}

and here's the json response sent by the server

["1--e0e43b1c-c48a-4456-bb4a-94ac3bf20512header.png", 
 "1--f4dcf831-dbf9-494b-b3cb-3f517f31667dheader.png", 
 "1--364ff0b9-a91c-4dfb-9bb8-8288b6e5d495header.png", 
 "1--1a4e75ea-4631-4249-afe8-9d39048e749bheader.png",
 "1--55f26351-0575-4b55-8f81-e8924eaaa613header.png"]

Upvotes: 1

Views: 1266

Answers (1)

John Boker
John Boker

Reputation: 83699

not sure if this helps but Length needs to be all lower case.

ie: data.length

Upvotes: 2

Related Questions