danny
danny

Reputation: 475

why Jquery .load() function is not firing on success?

I have made a jquery functions which suppose to do 3 steps

  1. onload it should replace attributes of all link files
  2. when clicking it should load a sub page into $("#content")
  3. again it should refire the function which would replace all links again

the following code works till 2 steps but doesnt fire third step which should replace all urls again I think it should replace also the links of loaded page?

$(document).ready(function(){
   var base_url = "http://localhost/dolphin/";
   $("a").each(function(e){
   if(this.href == "javascript:void(0)" || 
        this.href == base_url || 
        this.href == base_url + "index.php" || 
        this.href == "javascript:void(0);" || 
        this.href == "javascript:%20void(0)") {

     }else{
       page = 'Javascript:LoadPage(\''+ this.href + '\')';
       this.setAttribute('onclick',page);
       this.setAttribute('href', '#');
     }
   });
});

function LoadPage(url){
   $("#contentarea").load(url, function() {
     //after loading it should call redoIt() but it doesnt.
      redoIt();
   });
}

function redoIt(){
    var base_url = "http://localhost/dolphin/";
    $("a").each(function(e){
       if(this.href == "javascript:void(0)" || 
          this.href == base_url + "index.php" || 
          this.href == "javascript:void(0);" || 
          this.href == "javascript:%20void(0)") {

       }else{
         page = 'Javascript:LoadPage(\''+ this.href + '\')';
         this.setAttribute('onclick',page);
         this.setAttribute('href', '#');
       }
   });
 }

Upvotes: 0

Views: 171

Answers (1)

wzub
wzub

Reputation: 324

Your call to $.load is inside a function, and from what I gather you're not calling that anywhere so it's not getting executed. Take it out and it should work fine

$("#contentarea").load(url, function() {

//after loading it should call redoIt() but it doesnt.
 redoIt();
});

Upvotes: 1

Related Questions