Ajax не работает с jquery Flip! плагин
Я пытаюсь использовать ФЛИП! плагин и его содержимое загружается с помощью ajax. Я столкнулся с проблемой, хотя. Это просто не работает.
Я могу видеть событие post, происходящее в firebug, но, кажется, ничего не меняется, когда я заполняю параметр "content" внутри FLIP! подключить
Ниже мой код, который может объяснить вещи лучше.
<script type="text/javascript">
function getFlipContent(url,command, target){
$.post(url, {"data": command}, function(response) {
console.log(response);
//return response; // this is not working
replaceHtml(target,response); // workaround but kinda not really
});
}
function replaceHtml(object,html){
$(object).html();
$(object).html(html);
}
$(function(){
$(".flipable2").bind("click", function() {
var url= $(this).data("url");
var command= $(this).data("command");
var target = $(this).data("target");
//alert(flip);
if (target === undefined) {
flip = "self";
}
if (target == "self") {
$($(this)).flip({
direction: 'lr',
color: '#ffffff',
content: function() {
getFlipContent(url, command, target);
}
});
return false;
}
else {
$(target).flip({
direction: 'lr',
color: '#ffffff',
content: function() {
getFlipContent(url, command, target);
}
});
return false;
}
});
});
</script>
<body>
<div id="header">
<table width="100%" cellpadding="0px" border="0px" cellspacing="0px">
<tr>
<td><a href="#" class="flipable2 box" data-target="#page" data-url="test.php" data-command="test">FLIP</a></td>
</tr>
</table>
</div>
<div id="page" class="box">
BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH BLAH</td>
</div>
Так что сейчас я использую функцию replacechtml, чтобы вручную переписать содержимое цели, которую я только что "перевернул". Эта сортировка работает, но нарушает анимацию, поэтому я действительно предпочел бы использовать параметр содержимого плагина... Когда я делаю это, он просто ничего не делает. Анимация завершается, но содержимое не изменяется. Я думаю, что, возможно, я что-то упустил. Любая помощь приветствуется.
Вот также jsfiddle: http://jsfiddle.net/mUhuN/9/ хотя я не был уверен, как подделать запрос ajax.
В любом случае, пожалуйста, помогите:)
1 ответ
Попробуйте использовать обратные вызовы для загрузки Ajax перед анимацией:
$("#flipbox").flip({
direction:'tb',
onBefore: function(){
console.log('before starting the animation');
},
onAnimation: function(){
console.log('in the middle of the animation');
},
onEnd: function(){
console.log('when the animation has already ended');
}
})