I am requesting a JSON response via $.ajax in my rails project.
jQuery ->
testAjax()
testAjax = ->
$.ajax
url: "/gmap/test"
data: "id=2"
type: "GET"
dataType: "json"
complete: (data_response) ->
result = $.parseJSON(data_response)
alert(result.name)
I seem to get a correct json string back (according to Firebug console), which looks like this:
{"name":"Space Needle","latitude":47.620471,"longitude":-122.349341}
However, I get an error complaining “TypeError: result is null”
If I use
alert(data_response.responseText)
in the complete function, I get the json string. So the problem seems to be the parsing. (???)
Dooh! Thanks @KevinB, your comment about
successandcompletehas solved it. It’s so simple, use the former instead of the latter: