Monday, May 14, 2012

How to return "text/html" content for AJAX call using a template engine in sinatra?

SO, I have a problem with Ajax (using JQuery) and Sinatra.



I have a route:



get '/ajx' do
content_type 'text/html', :charset => 'utf-8'
slim :mypartitial, :layout => false
end


which is to be called via Ajax "GET":



  $(document).ready(function() {
$('#vars').click(function(event){
$.ajax({
type: "GET",
url: "/ajx",
data: "",
success: function(data) {
$("#result").html(data)
}
});
});
});


But I get no html output and nothing is rendered. I suppose the problem is here



 slim :mypartitial, :layout => false


but I have no idea how to return a valid html still using the template engine.





No comments:

Post a Comment