$.ajax
Rails プロジェクトでJSON レスポンスをリクエストしています。
jQuery ->
testAjax()
testAjax = ->
$.ajax
url: "/gmap/test"
data: "id=2"
type: "GET"
dataType: "json"
complete: (data_response) ->
result = $.parseJSON(data_response)
alert(result.name)
(Firebug コンソールによると) 正しい json 文字列が返されたようです。これは次のようになります。
{"name":"Space Needle","latitude":47.620471,"longitude":-122.349341}
ただし、「TypeError: 結果が null です」というエラーが表示されます。
私が使用する場合
alert(data_response.responseText)
関数ではcomplete
、json 文字列を取得します。したがって、問題は解析にあるようです。(???)