When trying to dynamically load a Javascript file using jQuery I keep getting a "not well-formed" error message. I have found people with similar problems on here but have yet to see a resolution provided.
My main script uses:
$.ajax({
url: 'test.js',
dataType: 'script',
cache: true,
success: loadScriptReturn
});
function loadScriptReturn() { }
My dynamically loaded script (test.js) in its simplest form:
alert('Hello World.');
Since I am specifically loading this as a script MIME type it eliminates the possibility that Firefox is confused as to what type of file is being pulled in. Is there a way to solve this problem? Alternatively, is there a way to shut off this specific error in Firefox? (note: this is an error, not a warning, which is extremely annoying because I do want to see subsequent error messages -- bad on Firefox as this should have been a warning, not an error)
Keep in mind, this example WORKS, but it still produces an error. Given how many scripts I need to load dynamically it will be tedious trying to sort through "real" error messages if I can't find a way to get rid of this.
Thank you in advance to contributors!
I found several questions that may help you:
The general consensus is that you need to change the MIME type to application/json
.