views:

558

answers:

3

I get the following warning in chrome developer javascript console:

Uncaught SyntaxError: Unexpected token < http://.../Question.asmx/js (line 1)

Resource interpreted as script but transferred with MIME type text/html. http://.../Question.asmx/js

The HTML source code looks fine:

<script src="../../../Question.asmx/js" type="text/javascript"></script>

I use ASP ScriptManager to include those web services. They work fine, I was just wondering what exactly the problem is and, because I have an OCD problem, how to get rid of the warnings.

EDIT: There is no custom handler involved. It's just a standard WebService that I include by using the scriptmanager:

<asp:ScriptManager runat="server" ID="scm1" EnablePageMethods="true" EnablePartialRendering="true" >
        <Services>
            <asp:ServiceReference Path="~/Question.asmx" />
        </Services>
    </asp:ScriptManager>
+1  A: 

The second warning is because your custom handler (Question.asmx) is not setting the mime type of the resource you're sending back correctly.

You should add the following to the ProcessRequest method:

context.Response.ContentType = "text/javascript";

That will probably also get rid of the first error, as an HTML page should start with a <!Doctype element to be valid, which is what I believe that error is complaining about.

Zhaph - Ben Duguid
I edited my question. There is no ProcessRequest method to override.
Stefan
A: 

Not sure what is the cause of the error in Chrome, but one way to avoid it would be to embed the javascript for the service proxy (question.asmx/js) directly in your page. This means a larger client download but one less round trip to the server (or two less trips depending on your site's authentication method).

Just set InlineScript="true" in the ServiceReference tag

For a bit more info, see http://weblogs.asp.net/dwahlin/archive/2006/12/28/understanding-asp-net-ajax-web-service-proxies.aspx

aponzani