views:

34

answers:

3

I have 2 identical xhtml-documents which are in html (1st) and xhtml (2nd) extensions. The difference is in extension only.

Using ajax (jQuery 1.4.1) I try to get 1st, but web server (IIS 5.1) sends response with Content-Type: text/html instead of application/xhtml+xml. If I try to get 2nd, there are no problems.

For both documents I use $.ajax( {...} ), but I get an error for 1st (in the comments):

$.ajax({ 
  url: url, 
  dataType: 'xml', 
  contentType: 'application/xhtml+xml', 
  success: function(data, ts, theXhr) { ... },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
    // textStatus = "parsererror"
    // errorThrown.lineNumber = 5193
    // errorThrown.message = "data is null"
    // errorThrown.name = "TypeError"
  }
});

---

How to make [any] web server think that the 1st document is a real xhtml?

A: 

Is the 1st document well formed etc? Parse error could mean invalid xml.

matpol
1st is correct because 2nd is correct; they are identical.
Desperadeus
A: 

AFAIK IIS uses file extensions to detect the content-type. You can see the MIME-Type map in the IIS configuration page.

Michael Stoll
The server can be not only IIS.
Desperadeus
MIME-Type mapping is server specific. I don't know how other servers detect the MIME-Type
Michael Stoll
A: 

How to make [any] web server think that the 1st document is a real xhtml?

From javascript the answer is: You can't. The webserver makes the decision as to what Content-Type to send.

If you control the server: You can configure IIS to send the correct Content-Type

If you don't control the server: There's not much you can do besides using a server-sided script to get the page and send the correct header.

How to add content-types in IIS 5.0 (from msdn):

Adding MIME Types to IIS 5.0

MIME types can be registered in IIS 5.0 using the IIS snap-in.

For example, to add the XML MIME type to the default Web site using the IIS snap-in:

  1. Select Default Web Site and bring up the Properties dialog box.
  2. Select the HTTP Headers tab.
  3. Under MIME Map, click the File Types tab and select New Type.
  4. Type .xml in the Extension field and text/xml in the Content Type field, and then click OK.

To add the XML MIME type to all sites running on a given machine:

  1. Select Internet Information Services and bring up the Properties dialog box.

  2. Under Computer MIME Map, click the Edit button and select New Type.

  3. Type .xml in the Extension field and text/xml in the Content Type field, and then click OK.

Any other extensions, such as .xsl (eXtensible Style Sheets), may be added using the same procedures.

Just change .xml and text/html with the extensions/content-type you want

Chris T
I am just interested in getting `application/xhtml+xml`. Is it possible do something in jQuery to trick the header before success processing?
Desperadeus
The error is probably thrown by the XmlHttpRequest so I don't think that's viable. I'd recommend either using the correct extension or adding a custom rule that maps `.html` to `application/xhtml+xml`
Chris T
Thanks for your advice, I'll map extensions for the rest kind of files if I have access to web server. It's an idea, but the problem as I could guess is somewhere in jQuery.
Desperadeus