0

I have master page (index.html). This page have 2 event click. when click ".eq(0)" there script load a external page with contenet javascript. when click ".eq(1)" there script clean "#Twitter_list" and load external page with contenet javascript. Ok work!. But.... I noticed that when I switch from one page to another javascript code on the previous page remains running how I do before loading a new page in ajax to clean the javascript code on the previous call page with ajax?

ent $("#header_container_menu" ).find('span').eq(0).click(function() {
 $.ajax({
    cache: false,
    type: "GET",
    url: "/pinguino/getPage.php",
    data: "PageID=TwitterList",
    dataType: "html",
    success: function(msg){
        $("#Twitter_list").html("");
        $("#Twitter_list").html(msg);
    },
    error: function(){
        alert("Chiamata fallita!!!");
     }
    });   


  })
  $("#header_container_menu" ).find('span').eq(1).click(function() {
    $.ajax({
      cache: false,
      type: "GET",
      url: "/pinguino/getPage.php",
      data: "PageID=TwitterPassword",
      dataType: "html",
    success: function(msg){
        $("#Twitter_list").html("");
        $("#Twitter_list").html(msg);
    },
    error: function(){
        alert("Chiamata fallita!!!");
    }
    });
  })

enter code here

  • javascript is single-threaded. If the script were still running, you wouldn't be able to click on anything. Do you mean it's still running asynchronous functions like `setInterval` or animations? – Barmar Aug 19 '14 at 12:24
  • I think he is talking about: if he ran second ajax he want to stop/cancel executing previously ajax if it is still in progress – Nikita Holovach Aug 19 '14 at 12:30
  • Check this one http://stackoverflow.com/questions/446594/abort-ajax-requests-using-jquery – Nikita Holovach Aug 19 '14 at 12:32

0 Answers0