JQuery ajax request throws invalid error in Firefox

When trying to dynamically load a Javascript file using jQuery, I keep getting a "malformed" error. I found people with similar problems here but haven't seen the resolution yet.

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 getting confused as to what type of file is being pulled in. Is there a way to solve this problem? Also, is there a way to disable this particular error in Firefox? (note: this is an error, not a warning, which is extremely annoying because I want to see subsequent error messages - bad in Firefox as it should have been a warning, not an error)

Be aware that this example is WORKS, but it still throws an error. Given how many scripts I need to dynamically load, it will be tedious trying to sort through the "real" error messages if I can't find a way to get rid of it.

Thanks in advance to the authors!

+3


source to share


2 answers


I found several questions that might help you:



The general consensus is that you need to change the MIME type to application/json

.

+2


source


Best way to load script dynamically:



$('head').append('<script type="text/javascript" src="test.js"></script>');

      

+1


source







All Articles