$ .get和回调在它的时间之前执行

时间:2011-04-11 12:49:22

标签: jquery callback get

此函数使用$ .get加载内容,在回调中我调用jquery插件(翻转)函数,该函数使用新内容“播放”(给出动画效果),

function editar_item(id, tipo) {
    var div = 'link';
    if (tipo == 0) {} else if (tipo == 1) {
        div = 'pregunta';
    } else if (tipo == 2) {
        div = 'file';
    }

    $.get('/includes/router.php?que=editar_item&id=' + id + '&tipo=' + tipo, function (data) {
        $("#" + div + id).flip({
            direction: 'tb',
            content: data,
            color: '#F9F9F9',
            onEnd: function () {
                console.log('when the animation has already ended');
            }
        });

    });
    return false;
}

它有效,但jquery插件在加载的内容之前调用它执行,我无法正确看到'效果',

任何想法为什么?

1 个答案:

答案 0 :(得分:1)

您的回调应该是第三个参数,您将其用作第二个参数。试试:

$.get('/includes/router.php?que=editar_item&id='+id+'&tipo='+tipo, {},  function(data) {
   // ...etc