When using jQuery's getScript() function I get a "not well-formed" error on a line with comments
Asked Answered
S

3

5

My guess is that the src file needs to be XML-friendly, but of course none of the JS file is since it's using all sorts of non-XML compliant entities.

getScript() may be expecting an XML file =/

Any thoughts?

    if(is_def(pObj)){
      $.getScript(pObj.src,function(){
            pObj.stat = STATUS_OK;
            $a.dequeue(pObj);         
      });

    }

I'm also developing this on my desktop, not using any servers

Segregationist answered 16/3, 2010 at 23:12 Comment(0)
M
1

jQuery's official docs don't say anything about expecting XML. It would seem that it simply expects a normal javascript file. I also tried some simple tests loading javascript files with comments in them and didn't have any problems.

I have a feeling that you either have a syntax error in the javascript file or the ajax call is 404'ing.

Here are some suggestions.

  • If your browser supports it, do a console.log(pObj.src) to make sure that the script URL stored in that variable is correct.
  • Try pasting the javascript code directly into the main javascript file and see if it causes any syntax errors there.
  • Use the $.ajax method to manually achieve the same effect.
Millham answered 16/3, 2010 at 23:48 Comment(0)
B
9

As far as I can see this is a Firefox bug and the error message is actually spurious. In my testing it also only occurs when using getScript() without a web server. If you open the pages where getScript() is used on a web server the error isn't fired. I think you can safely ignore it, as even Firefox doesn't flag it as a critical script-stopping error. Everything works normally and most users will never see it.

Bracken answered 23/7, 2011 at 15:42 Comment(1)
+1 the error was there because I was getting the script from my machine. Tested by uploading and it went away.Hypostatize
M
1

jQuery's official docs don't say anything about expecting XML. It would seem that it simply expects a normal javascript file. I also tried some simple tests loading javascript files with comments in them and didn't have any problems.

I have a feeling that you either have a syntax error in the javascript file or the ajax call is 404'ing.

Here are some suggestions.

  • If your browser supports it, do a console.log(pObj.src) to make sure that the script URL stored in that variable is correct.
  • Try pasting the javascript code directly into the main javascript file and see if it causes any syntax errors there.
  • Use the $.ajax method to manually achieve the same effect.
Millham answered 16/3, 2010 at 23:48 Comment(0)
S
1

I guess the server just sets the wrong content type on the response and thus your browser may try to interpret the returned data as XML/HTML instead of javascript.

Made a quick demo: http://jsbin.com/ilepu/2 which loads from http://jsbin.com/avewo/2. Everything works as expected load script contains comments too

Saporous answered 17/3, 2010 at 0:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.