2010-10-22 150 views
0

我正在編寫的腳本here加載一個頁面在div中,但腳本開始運行,並在中間al功能停止自己。如果我將代碼行向上移動,將運行第一行,然後停止。Ajax腳本本身停止

我的代碼是:

function loadDemo(path) { 
$.get(path, function(data) { 
    alert("Chiamata la funzione get per " + path + "!"); 
    data = data.replace(/<script.*>.*<\/script>/ig,""); // Remove script tags 
    data = data.replace(/<\/?link.*>/ig,""); //Remove link tags 
    data = data.replace(/<\/?html.*>/ig,""); //Remove html tag 
    data = data.replace(/<\/?body.*>/ig,""); //Remove body tag 
    data = data.replace(/<\/?head.*>/ig,""); //Remove head tag 
    data = data.replace(/<\/?!doctype.*>/ig,""); //Remove doctype 
    data = data.replace(/<title.*>.*<\/title>/ig,""); // Remove title tags 
    data = data.replace(/<iframe(.+)src=(\"|\')(.+)(\"|\')>/ig, '<iframe$1src="'+'/'+section+'/'+'$3">');; // Change iframe src 
    data = data.replace(/<img([^<>]+)src=(\"|\')([^\"\']+)(\"|\')([^<>]+)?>/ig, '<img$1src="'+'/'+section+'/'+'$3" $5/>');; // Change images src 
    $('#dataframe').empty(); 
    data = $.trim(data); 
    alert("A questo punto dovrei possedere i dati..."); 
    $('#dataframe').empty().html(data); 
}); 
} 

$(document).ready(function() { 
if (window.location.hash == "") { 
    window.location.hash = "homepage"; 
} 
//Rewrite and prepare links of right-hand sub navigation 
$('#tabs a').each(function() { 
    $(this).attr('target', 'dataframe'); 
    $(this).click(function(e) { 
    alert("E' stato cliccato un bottone magico!"); 
    $(this).parents('ul').find('li').removeClass('ui-tabs-selected ui-state-active'); 
    $(this).parents('ul').find('li').addClass('ui-state-default'); 
    alert("Rimossa la classe!!"); 
    $(this).parent().addClass('ui-tabs-selected ui-state-active'); 
    alert("Aggiunta la classe!!!"); 
    alert("Il nuovo location sarà " + this.getAttribute('href').match((/\/([^\/\\]+)\.asp/))[1]); 
    //Set the hash to the actual page without ".asp" 
    window.location.hash = this.getAttribute('href').match((/\/([^\/\\]+)\.asp/))[1]; 
    alert("Ho aggiornato l'hash con " + window.location.hash); 
    loadDemo(this.getAttribute('href')); 
    alert("In teoria mi fermo qui.."); 
    e.preventDefault(); 
    }); 
}); 

alert(window.location.href); 
//If a hash is available, select the right-hand menu item and load it 
if(window.location.hash) { 
    loadHash(); 
} 
listenToHashChange(); 
}); 

$(window).bind('load', function() { 
//If we use it as docs page, go to the selected option 
if(window.location.hash) { 
    gotoHash(); 
} 
}); 

function listenToHashChange() { 
var savedHash = window.location.hash; 
alert("SavedHash = " + savedHash); 
window.setInterval(function() { 
    if(savedHash != window.location.hash) { 
    savedHash = window.location.hash; 
    if(window.location.hash) 
    gotoHash(); 
    } 
},200); 
} 
function loadHash() { 
$('#tabs a').each(function() { 
    if(this.getAttribute('href').indexOf('/'+window.location.hash.substr(1)+'.asp') != -1) { 
    $(this).parents('ul').find('li').removeClass('ui-tabs-selected ui-state-active'); 
    $(this).parent().addClass('ui-tabs-selected ui-state-active'); 
    loadDemo(this.getAttribute('href')); 
    } 
}); 
} 
function gotoHash() { 
var hash = window.location.hash.substr(1).split('-'); 
var go = hash[1] ? hash[1] : hash[0]; 
} 

和不工作的部分是做$(this).parent().addClass('ui-tabs-selected ui-state-active');alert("Aggiunta la classe!!!");

回答

0

後我不是jQuery的專家,所以它比答案更多的猜測,但$(this).parent()不會返回你已經移除了body