After initiating an AJAX request to a method in my controller, I am attempting to display a partial. Below is the AJAX call I am currently using:
$('.savings_link').click(function(event){
$.ajax({
type: 'GET',
url: '/topics/savings_easter_egg',
data: {
savings: data[key]['saving']
} ,
dataType: 'json',
});
event.preventDefault(); // To prevent the link from following its href
});
The AJAX call successfully reaches my controller method where I aim to return and display a partial.
def savings_easter_egg
@savings = params[:savings] if params[:savings]
return render :json => {
:html => render_to_string({
:partial => "topics/savings",
:locals => { :savings => @savings }
})
}
end
Upon inspecting with firebug, I received the response:
{"html":"<p>Hi</p>"}
This response reflects my desired partial topics/savings, however, the page fails to reload or display the partial as intended.
I am seeking guidance on how to effectively redirect or display the actual partial. Any suggestions?