对话框(“关闭”)在ajax:success事件处理程序内不起作用 [英] dialog("close") doesn't work inside ajax:success event handler

查看:206
本文介绍了对话框(“关闭”)在ajax:success事件处理程序内不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery对话框来让用户登录。我正在使用ajax和devise。用户登录后,对话窗口应该关闭。我在bind(ajax:success)中放置对话框(close),但它不起作用,我收到错误:



在初始化之前不能调用对话框的方法;尝试调用方法close



代码 br />

  $(function(){
$(#sign_in)。 {
$('< div id =box>')。dialog({
open:function(){
var that = this;
$ )。(/ users / sign_in,function(){
$(#new_user)bind(ajax:success,function(evt,data,status,xhr){
$(div#utility)。html('welcome'+ data.user +'|< a href =/ users / sign_outdata-method =delete =nofollow>注销< / a& ;');
$(that).dialog('close');
})
})
},
标题:'登录'
});
});
})

任何人都可以帮我弄清楚问题是什么????谢谢

解决方案

这里有一个问题,可以帮助您解决问题。



jQuery:通过Ajax加载模式对话框



你也可以更改对话框的选择器 $('#box')。对话框({...



ajax成功回调(在您进行更改后)您可以执行 $('#box')。对话框('close')





$ b

  $(function(){
$( ($ {
'('#box')。对话框({
open:function(){
$(this).load(/ users /签到);
},
标题:'登录'
});
});

$(#new_user)。bind(ajax:success,function(evt,data,status,xhr){
$(div#utility)。html 'welcome'+ data.user +'|< a href =/ users / sign_outdata-method =delete =nofollow>登出< / a>');
$(' #box')对话框('close');
})
})


I am trying to using jQuery dialog to make a user sign in. I am using ajax and devise. After users sign in, the dialog windows should close. I put dialog("close") inside bind("ajax:success"), but it doesn't work and I get error:

"cannot call methods on dialog prior to initialization; attempt to 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 anyone help me figure out what the problem is?
thanks

解决方案

here is a question that has answers that might help with your problem.

jQuery: Load Modal Dialog Contents via Ajax

you can also change your selector for the dialog to $('#box').dialog({ ...

and in your ajax success callback (after you make changes) you can do $('#box').dialog('close')

EDIT: this 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');
   })
}) 

这篇关于对话框(“关闭”)在ajax:success事件处理程序内不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆