I'm trying to load a javascript file locally with getScript, but it returns a 404 error.
test.js - the script I'm trying to load:
var hello = function(){
alert( "test" );
}
hello();
jQuery code from index.html:
<script type='text/javascript'>
$.getScript( "js/test.js" )
.fail( function( e ){ $( 'body' ).html( JSON.stringify( e ) ) } )
.done( function(){ alert( "Success" ) } );
</script>
When I open index.html in Chrome, getScript fails, and the following is displayed in the body:
{"readyState":4,"responseText":"","status":404,"statusText":"error"}
So obviously jQuery can't find the file specified. But the weird thing is, when I use the traditional tags:
<script type='text/javascript' src='js/test.js'></script>
it works fine.
Also, getScript works fine if I'm loading from an external site, such as:
$.getScript( "http://www.youtube.com/player_api" )
So what could be the problem?