3

I do many search in stackoverflow and google, but I cannot found a logical way !

I use getScript to load a js file, I get "Not Well Formed" error in Firefox error console. I trying to comment all lines of my code in js file, and again I get that error !

Timestamp: 04/25/2012 02:02:32 PM
Error: not well-formed
Source File: file:///G:/ct/main/main.js?_=1335346352617
Line: 1, Column: 1
Source Code:
/*

I use $.ajax too, I get exactly that error.

Note: my included JS code work without any problem and everything is OK (when my code is not commented), but I want to know why my user should get this error in Firefox ?!

Sorry for my bad English.

EDIT:

var ulWidth = 0; 
$('.carousel_links ul li').each(function(){ 
  ulWidth += $(this).outerWidth(); 
}); 

$('.carousel_links ul').css({ 
   'width' : ulWidth+'px' 
}); 

UPDATE:

I found this way: How do I include a JavaScript file in another JavaScript file?

I use this and I think this way is better than $.getScript because I don't get any error and all of my JavaScript code work fine.

Community
  • 1
  • 1
MajAfy
  • 3,007
  • 10
  • 47
  • 83
  • ...Well what's the code? – Jivings Apr 25 '12 at 09:44
  • @Jivings I wrote a jQuery code, as I said, my jquery code work fine, for example if I delete all lines in JS file and add just `alert('OK');` the Alert box will show and everything is ok but I got that error again – MajAfy Apr 25 '12 at 09:46
  • Show your loadScript code then. More information is needed here before an answer can be deduced. – Jivings Apr 25 '12 at 10:05
  • @Jivings this is my JS code : `var ulWidth = 0; $('.carousel_links ul li').each(function(){ ulWidth += $(this).outerWidth(); }); $('.carousel_links ul').css({ 'width' : ulWidth+'px' }); ` – MajAfy Apr 25 '12 at 10:08
  • The code that's being loaded? – Jivings Apr 25 '12 at 10:50
  • @Jivings Yes this code is in my js file and load without any problem – MajAfy Apr 25 '12 at 10:56
  • I can't see anything wrong with this. Are you sure you've provided as much information as possible? – Jivings Apr 25 '12 at 13:13

1 Answers1

0

I think it must be do do with the mime type of the requested document.

If it's running on your server, make sure that it knows what to do with .js files. It should return text/javascript.

If not then it should definitely work when requested like this:

var req = new XMLHttpRequest();
req.open("GET", "filename.js");
req.overrideMimeType("text/javascript");
req.send(null);
Jivings
  • 22,834
  • 6
  • 60
  • 101