Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't execute code from a freed script error

Status
Not open for further replies.

Edward07

Programmer
Apr 13, 2007
49
NL
I am getting in to this error each time i try to load the following javascript page. But if i do a refresh the error goes away. could any one tell me how to avoid such error at first place?Thanks

Can't execute code from a freed script

pointing at bold part:

function WindowLoad(func)
{
var prev=window.onload;
window.onload=function(){ if(prev)prev(); func(); }
}


Code:
<html>

<body>

<script>
<!--

var REFRESH_TIME = 7000;
var requester;
var musicListRequester;
var timerId;

function getElementById(totalvotes) 
{
	if (document.all)
  	{
  		return document.all(totalvotes);
  	}
	else if (document.getElementById)
	{
		return document.getElementById(totalvotes);
  	}
}

function WindowLoad(func)
{
	var prev=window.onload;
	window.onload=function(){ if(prev)prev(); func(); }
}

function WindowUnload(func)
{
	var prev = window.onunload;
    window.onunload=function() { if(prev)prev(); func(); }
}

WindowLoad(init);
WindowUnload(shutdown);

function init()
{
	onTimerFired();
}


function onTimerFired()
{
	
	
	field = getElementById("Last5Songs");
	if (field)
	{
		fetchMusicList("./script.php");		
	}

  

    timerId = self.setTimeout("onTimerFired()", REFRESH_TIME);
}


function fetchMusicList(url)
{
	if(window.XMLHttpRequest)
	{
    	try
    	{
			musicListRequester = new XMLHttpRequest();
        }
        catch(e)
        {
			musicListRequester = false;
        }
    }
    else if (window.ActiveXObject)
    {
		try
		{
        	musicListRequester = new ActiveXObject("Msxml2.XMLHTTP");
      	}
      	catch(e)
      	{
        	try
        	{
          		musicListRequester = new ActiveXObject("Microsoft.XMLHTTP");
        	}
        	catch(e)
        	{
          		musicListRequester = false;
        	}
		}
    }

    if (musicListRequester)
	{
		musicListRequester.onreadystatechange=musicListFetched;
		musicListRequester.open("GET", url);
		musicListRequester.send(null);
	}
}


function musicListFetched()
{    
if (musicListRequester.readyState == 4 && musicListRequester.status == 200)    
{       
 var output = "";      
  var songs = musicListRequester.responseXML.getElementsByTagName('playlist')[0].getElementsByTagName('song');  
                  for (var i = 0; i < songs.length; i++)    
    {           
 root = songs[i];                 
           var artist = root.getElementsByTagName("artist")[0].firstChild.nodeValue;    
        var song = root.getElementsByTagName("name")[0].firstChild.nodeValue;    
        var image = root.getElementsByTagName("image")[0].firstChild.nodeValue;    
        var rating = root.getElementsByTagName("rating")[0].firstChild.nodeValue;     
       var songid = root.getElementsByTagName("songid")[0].firstChild.nodeValue;     
       var totalvotes = root.getElementsByTagName("totalvotes")[0].firstChild.nodeValue;         
               

output = output + (i+1) + ") " + artist +  "         -          " + song + "-          " + image + "-          " + rating + "-          " + songid + "-          " + totalvotes + ""; 
output += ' <input type="checkbox" name="totalvotes" value="' + totalvotes +'" /><br />'; 

       }                document.getElementById("Last5Songs").innerHTML = output;   

 }

}

// -->
</script>

   <td class="text_box" vAlign="top" bgColor="#ffffff" height="50" width="893">
        <div id="Last5Songs" style="width: 888; height: 39">
       
&nbsp;</div>
        </td>

</body>

</html>
 
I think you are making this code way more complex than it needs to be.

I'm lost as to what it's supposed to do exactly.





[monkey][snake] <.
 
Thank you for both replies. The script is fetching dynamic xml data from php every few seconds and display it using ajax. Any time i load the script it shows this error :

Can't execute code from a freed script

pointing at bold part:

function WindowLoad(func)
{
var prev=window.onload;
window.onload=function(){ if(prev)prev(); func(); }
}

Then when i hit f5 then the error willn't show!!
 
prev" and "func" are local variables that are not being defined in the function you are creating. Try turning them into global variables and see if it starts working.
Code:
var previousOnload;
var newOnload;
function WindowLoad(func)
{
    previousOnload=window.onload;
    newOnload = func;
    window.onload=function(){ if(previousOnload)previousOnload(); newOnload(); }
}

Another example can be found in faq216-4862.

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top