Html – inject html using ajax

ajaxhamlhtml

I have a HAML page with some div elements. I need to inject this into a div on another page when a button is clicked. how do i do this? thanks

Best Solution

You have to add the jQuery plugin from jQuery.com. you can download the plugin or use the link http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js as src in the js file.

then use the follwing code

$(document).ready(function(){
  $("#your_button_Id").click(function(){
    $.ajax({
      url: "test.html",
      context: document.body,
      success: function(response){
        $('#div_Id').html(response);
      }
    });
  });
});

Hope this helps!!! happy coding.