How does web server detect Content-Type for a response document?
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
开发者_C百科// errorThrown.message = "data is null"
// errorThrown.name = "TypeError"
}
});
---
How to make [any] web server think that the 1st document is a real xhtml?
Is the 1st document well formed etc? Parse error could mean invalid xml.
AFAIK IIS uses file extensions to detect the content-type. You can see the MIME-Type map in the IIS configuration page.
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:
- Select Default Web Site and bring up the Properties dialog box.
- Select the HTTP Headers tab.
- Under MIME Map, click the File Types tab and select New Type.
- 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:
Select Internet Information Services and bring up the Properties dialog box.
Under Computer MIME Map, click the Edit button and select New Type.
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
精彩评论