jquery - dialog("close") doesn't work inside ajax:success event handler -
i trying using jquery dialog make user sign in. using ajax , devise. after users sign in, dialog windows should close. put dialog("close") inside bind("ajax:success"), doesn't work , error:
"cannot call methods on dialog prior initialization; attempt call method 'close'"
code:
$(function(){ $(" #sign_in").click(function(){ $('<div id="box" >').dialog({ open: function(){ var that=this; $(this).load("/users/sign_in",function(){ $("#new_user").bind("ajax:success",function(evt,data,status,xhr){ $("div#utility").html('welcome'+data.user+' |<a href="/users/sign_out" data-method="delete" rel="nofollow">sign out</a> ') ; $(that).dialog('close'); }) }) }, title: 'sign in ' }); }); })
can me figure out problem is?
thanks
here question has answers might problem.
jquery: load modal dialog contents via ajax
you can change selector dialog $('#box').dialog({ ...
and in ajax success callback (after make changes) can $('#box').dialog('close')
edit: work?
$(function(){ $(" #sign_in").click(function(){ $('#box').dialog({ open: function(){ $(this).load("/users/sign_in"); }, title: 'sign in ' }); }); $("#new_user").bind("ajax:success",function(evt,data,status,xhr){ $("div#utility").html('welcome'+data.user+' |<a href="/users/sign_out" data-method="delete" rel="nofollow">sign out</a> ') ; $('#box').dialog('close'); }) })
Comments
Post a Comment