javascript - jQuery ajax request causes 'not well-formed' error in Firefox - Stack Overflow

When trying to dynamically load a Javascript file using jQuery I keep getting a "not well-formed&q

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!

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!

Share Improve this question asked Apr 3, 2012 at 15:26 OrangeFrogOrangeFrog 2954 silver badges12 bronze badges 4
  • I doubt this is Firefox giving you this message. More likely Firebug. – Mark Fraser Commented Apr 3, 2012 at 15:29
  • Yes, probably Firebug - in addition, you should not be using ajax() to fetch JS script - you should be using getScript() api.jquery./jQuery.getScript - While one is shorthand for the other, it is more clear. – Dutchie432 Commented Apr 3, 2012 at 15:31
  • Also check your encoding. If you are using UTF-8, make sure that you arn't using a BOM because this can cause all sorts of headaches. – mekwall Commented Apr 3, 2012 at 15:32
  • You're right, Firebug error, but I did find a solution (see ment below)... thanks everyone for checking into this. I spent 3-4 hours yesterday and 1-2 hours today trying to figure this out. Turns out this is only thrown when using Ajax locally; remotely: no error. – OrangeFrog Commented Apr 3, 2012 at 16:56
Add a ment  | 

2 Answers 2

Reset to default 2

I found several questions that may help you:

  • not well-formed error in firefox
  • "not well-formed" error in Firefox when loading JSON file with XMLHttpRequest

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

A better way to load script dynamically:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745390166a4625624.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信