我有一個jQuery的問題,使AJAX調用後不工作。這是一個可以正常工作的拖放腳本,但當我想調用AJAX時它會停止。jQuery的Ajax調用後不工作
var ary1=new Array(5);
ary1[0]="container1";
ary1[1]="container2";
ary1[2]="container3";
ary1[3]="container4";
ary1[4]="main_container";
var ary2=new Array(5)
ary2[0]=0;
ary2[1]=0;
ary2[2]=0;
ary2[3]=0;
ary2[4]=4;
var i;
var srouce,dest;
var old;
$(window).load(function(){
$(function() {
$(".draggable").draggable();
$(".droppable, #droppable-inner").droppable({
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
drop: function(event, ui) {
//if(ui.draggable.parent().attr('id')=="container1")alert("Yep");
alert(ui.draggable.attr('id') + ' was dropped from ' + ui.draggable.parent().attr('id')+' into '+$(this).attr('id'));
$(this).addClass("ui-state-highlight");
// Move the dragged element into its new container
srouce= ui.draggable.parent().attr('id');
dest=$(this).attr('id');
for(i=0;i<5;i++){
if(srouce==ary1[i])break;} // to get src
alert(ary1[i]);
if((ary2[i]>0&&ary2[i]<=4&&ary1[i]=="main_container")|| (ary2[i]==1&&ary1[i]!="main_container"))
{
old=i;
ary2[i]--;
alert(ary2[i]); // decrement flag
for(i=0;i<5;i++){
if(ary1[i]==dest)break;}//to get dest
alert(ary1[i]);
if((ary2[i]==0&&ary1[i]!="main_container")|| (ary2[i]>=0&&ary2[i]<4&&ary1[i]=="main_container"))
{
ary2[i]++;//increment flag
alert(ary2[i]);
ui.draggable.attr('style','position:relative ;cursor:hand');// move the image
$(this).append(ui.draggable);
}
else
{
ary2[old]++;
ui.draggable.attr('style','position:relative ;cursor:hand');
ui.draggable.parent().append(ui.draggable);
}
}
return false;
}
});
});
});//]]>
1.在哪裏AJAX代碼? 2.'$(function ...)'與'$(document).load(function ...)'相同,你不需要兩者。 – Barmar 2013-02-23 11:48:35
是的,沒有AJAX代碼 - 你只是在頁面加載時調用嵌套函數 - @Barmar寫了這個。 – kbec 2013-02-23 12:16:41