Bill Robertson's Blog

Sys.ScriptLoadFailedException when adding ScriptReferences

I added a manual ScriptReference to an embedded resource but was receiving a client side error:

Error: Sys.ScriptLoadFailedException: The script <url for script> could not be loaded or does not contain the Sys.Application.notifyScriptLoaded() callback.

I found this post to help with the problem.  Ajax now loads the various script files in an asynchronous manner, and it is the responsibility of the script file, when completed to call execute code similar to the following:

if( Sys && Sys.Application ){
   Sys.Application.notifyScriptLoaded();
}

The if block might not be required, but if you are using a javascript file outside of Atlas you probably should protect it.  However on Luis's site, he missed a casing on the method call notifyScriptLoaded.  I'm sure he will get that fixed, but just be aware if you copy and paste.  :)

 

 

 

 

Comments

Jim said:

SWEET GEORGIA BROWN!!!  That was driving me crazy - fixed now thanks to you!

=)

# December 24, 2006 8:41 PM

Panagiotis Poulos said:

You are a life saver!!! I still can't believe I finally got it working - thanks to you!

Cheers!

# March 2, 2007 11:39 AM

Helen said:

I found that I was still getting error messages from IE when I was just checking if(Sys && Sys.Application) when I used the same javascript file in a non-ajax project.

I found that this solved the problem:

if( typeof(Sys) != "undefined" && typeof(Sys.Application) != "undefined" ){

  Sys.Application.notifyScriptLoaded();

}

# April 25, 2007 5:42 AM

G said:

If you're adding combined scripts using the ScriptManager control, apparently you no longer require this call.

Unfortunately I still periodically get it, most of the time when first compiling the app - think it's a bug in the control toolkit.  Or should I say - another bug in the toolkit lol...

# July 2, 2008 7:34 AM

Trevor said:

Thanks, these three lines were almost perfect.

I used Helens version (above) and everything works fine now.

But it feels odd having to write some code at the bottom of my js files.

# November 20, 2008 10:32 AM

Gerardo Contijoch said:

Thank you! This is what I was looking for.

I agree with Trevor, I don't like to add that script at the bottom of the js files. Can't ASP.NET AJAX auto notify itself when the scripts are loaded?

# December 15, 2008 10:56 AM

Kalyanaraman said:

I have common.js file in my project and I tried adding the 3 lines of code at the bottom of my .js file. But it didnt work out. Any help would be greatful.

# January 20, 2009 8:11 AM

Bill Robertson said:

@Kalyanaraman  Are you loading the file through the ScriptReference add method?

What error are you having?

# January 20, 2009 8:25 AM

manish said:

@ Helen LIFE SAVER i have been tryin to solve thisfor hours now...and two lines of code worked!!!!

any logic behind this ?

# July 29, 2009 3:16 PM

Swadeesh said:

Where can I put this code.

if( Sys && Sys.Application ){

  Sys.Application.notifyScriptLoaded();

}

I dont have any javascript file. I am just using update panel.

# August 29, 2009 11:37 AM