Alex
Alex

Reputation: 1274

How to close a popup window after sending ajax request to rails controller without reloading parent

I am in show view of a controller and if a user clicks on a link, a popup window with a form is displayed. If the user clicks "Submit", the form is submitted via ajax to a custom "action" in the same controller. In the action.js.erb partial I have the following code:

  window.opener.location.reload();
  window.close();

It works fine, but the whole show view page is reloaded. And I'd like just to have the focus back and write some div updates in the js.erb partial.

Upvotes: 1

Views: 5451

Answers (3)

Aswathy
Aswathy

Reputation: 674

In the associated action.js.erb file, add the following code.

function hideDialog() {
  var $dialog = $('#dialog_area');
  if ($dialog.is(':visible')) {  
    PageOverlay.hide();      
    $dialog.hide();
  }
  return this;
};

Upvotes: 0

Vik
Vik

Reputation: 5961

Instead of calling from helper , close the window on onsuccess event of Ajax.

success: function(g) {
  window.close(); OR $('#popup_id').hide();
  $('#div_id').html("Write message or other response form your action").
}

Upvotes: 1

MakuraYami
MakuraYami

Reputation: 3428

Use jquery to hide it once completed.

$('#popup_wrapper_id').fadeOut();

Upvotes: 1

Related Questions