Ajax脚本自行停止

时间:2010-10-22 10:23:35

标签: javascript jquery-ui jquery

我正在编写脚本here来加载div中的页面,但脚本开始运行,中间函数停止运行。如果我向上移动代码行,则运行第一个新行,然后停止。

我的代码是:

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!!!");

之后

1 个答案:

答案 0 :(得分:0)

我不是jquery专家,所以它更多的是猜测而不是答案,但$(this).parent()不会返回您已删除的body