Skip to content

Instantly share code, notes, and snippets.

@barreyro
Created January 8, 2015 03:55
Show Gist options
  • Save barreyro/2d019d98c3f3f3936ee5 to your computer and use it in GitHub Desktop.
Save barreyro/2d019d98c3f3f3936ee5 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$("body").on("click", "#signup", function(event){
event.preventDefault();
$target = $(event.target);
$.ajax({
type: "GET",
url: "/signup",
}).done(function(response){
$(".container").replaceWith(response);
})
})
$("body").on("click", "#login", function(event){
event.preventDefault();
$target = $(event.target);
$.ajax({
type: "GET",
url: "/",
}).done(function(response){
$(".container").replaceWith(response);
})
})
$(".edit_comment_link").click(function(event){
event.preventDefault();
$target = $(event.target);
$target.hide();
$(".edit_form_div").css('display','block');
})
$(".add_comment_button").click(function(event){
event.preventDefault();
$target = $(event.target);
$target.hide();
$(".comment_form").css('display','block');
})
$('#comment_block').on('submit', '.comment_form', function(event) {
event.preventDefault()
$target = $(event.target)
$.ajax({
type: "POST",
url: $target.attr('action'),
data: $target.serialize()
}).done(function(response){
console.log(response);
$target.parent().siblings('.userComments').replaceWith(response);
})
})
});
@lgvital
Copy link

lgvital commented Jan 8, 2015

I'd use success instead of done:

    $.ajax({
      type: "POST",
      url: $target.attr('action'),
      data:  $target.serialize(),
      success: function (data) {
        $target.parent().siblings('.userComments').replaceWith(response);
      }
   });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment