s15199d
s15199d

Reputation: 7717

XML can't be the whole program

When I include the following js file (with jquery in it), I get the error in Firebug "XML can't be the whole program"

JS file include reference:

<script src="~/Scripts/scriptname.js" type="text/javascript"></script>

JS file contents:

$("[id*='txtAddress1S']")
  .blur(function(){
   $("[id*='txtAddress1S']")
      .val().match(
          /\b[p]*(ost)*\.*\s*[o|0]*(ffice)*\.*\s*b[o|0]x\b/i)&&
         (alert("Packages are not deliverable to a Post Office Box.
         \nPlease provide a different shipping address."),
    $("[id*='txtAddress1S']").focus())
  });

Thanks in advance!

Upvotes: 10

Views: 8357

Answers (6)

Michael Berkowski
Michael Berkowski

Reputation: 270757

It might be that your script src attribute is not properly understood with the ~ and being parsed as an empty <script> tag instead. Use the full path to the javascript file, or a path relative to the page it's loading on:

<script src="/full/path/to/Scripts/scriptname.js" type="text/javascript"></script>
<script src="../relative/to/Scripts/scriptname.js" type="text/javascript"></script>

Upvotes: 10

khollenbeck
khollenbeck

Reputation: 16157

I experienced this same error today. In my case it was because I didn't use HTML codes for special characters in my URL while doing an AJAX request. For example...

Using &amp; instead of using &

Upvotes: 1

MiKryz
MiKryz

Reputation: 11

I found another reason for"XML can't be the whole program in FF and Uncaught SyntaxError: Unexpected token < in Chrome. In my case, everything was failing with ScriptResource.axd.

The reason was that I'm serving some pages from https and I have a manager switching between http and https requests depending on what is currently required. Due to incorrect configuration the manager was serving ScriptResource.axd always over http, which caused errors on https pages.

Upvotes: 1

a coder
a coder

Reputation: 7659

Just had the same error. Make sure the javascript include file does not contain < script> tags. Once those are pulled out of your include file, the error goes away (assuming that's all that is wrong).

Upvotes: 0

Mark Gibaud
Mark Gibaud

Reputation: 2061

Shooting from the hip: I actually got this error because I added a wildcard mapping for aspnet_isapi.dll in my IIS 5.1 / WinXP (for some MVC related work). This means .js files got processed by IIS differently. Once I removed the mapping, the error you describe disappeared.

Upvotes: 0

lonesomeday
lonesomeday

Reputation: 238045

For some reason, your script file is being treated by Firefox as an XML file. My guess is that you have included script tags in your Javascript file. E.g.

<script>
    $("[id*='txtAddress1S']").blur(function(){$("[id*='txtAddress1S']").val().match(/\b[p]*(ost)*\.*\s*[o|0]*(ffice)*\.*\s*b[o|0]x\b/i)&&(alert("Packages are not deliverable to a Post Office Box.\nPlease provide a different shipping address."),$("[id*='txtAddress1S']").focus())});
</script>

You don't need script tags in an external JS file.

The equivalent error in Chrome is

Uncaught SyntaxError: Unexpected token <

Upvotes: 4

Related Questions