$.getJSON With Spring Not Executing Callback

I've looked around for a while now, seen many similar problems, but none that help. I have a getJSON call that calls my Spring controller and responds with JSON text (Verified that JSON text is indeed being returned), but the callback is never executed (Based that nothing executes within the callback function and I don't receive errors with bad JavaScript).

In my jsp file:

function getUserText(str)
{
    $.getJSON("selectUser.htm", { id: str }, function(user)
    {
        //Doesn't matter what's here
    });
}

In my controller:

@RequestMapping(value="/selectUser.htm")
public @ResponseBody String SelectUser(@RequestParam String id)
{
    Users user = userMap.get(id);

    if (user == null)
        return null;

    return createUserJSON(user);
}

Answers


I'm not sure about this, but my guess is the function you provide is the success function that gets called when ajax returns. It is possible that the request is not returning successfully.


It means the JSON is invalid. It could be the content is invalid or the content-type is not correctly set....

$.getJSON has no error callback

http://api.jquery.com/jQuery.getJSON/

to see what the problem is you need to use

$.ajax({
  url: "myurl",
  type: "GET",
  dataType: "json",
  success: function() {
    //called when successful
  },
  error: function(e) {
    //called when there is an error
  },
});

Found the answer. Turns out that the JSON needs to be valid. I made a mistake so the JSON wasn't formatted correctly. I didn't know that the format mattered even before the callback function.


Need Your Help

Doing a LINQ join, then group by, then a sum on two different columns

c# linq join group-by sum

I am using LINQ to SQL in a project and I am having an issue doing both a join and a group by to do a comparison between the two fields that are in each table.