草案
此页面不完整。

XMLHttpRequest 方法 overrideMimeType() specifies a MIME type other than the one provided by the server to be used instead when interpreting the data being transferred in a request. This may be used, for example, to force a stream to be treated and parsed as "text/xml" , even if the server does not report it as such. This method must be called before calling send() .

句法

XMLHttpRequest.overrideMimeType(mimeType)
					

参数

mimeType
DOMString specifying the MIME type to use instead of the one specified by the server. If the server doesn't specify a type, XMLHttpRequest assumes "text/xml" .

返回值

undefined .

范例

This example specifies a MIME type of "text/plain" , overriding the server's stated type for the data being received.

注意: If the server doesn't provide a Content-Type header, XMLHttpRequest assumes that the MIME type is "text/xml" . If the content isn't valid XML, an "XML Parsing Error: not well-formed" error occurs. You can avoid this by calling overrideMimeType() to specify a different type.

// Interpret the received data as plain text
req = new XMLHttpRequest();
req.overrideMimeType("text/plain");
req.addEventListener("load", callback, false);
req.open("get", url);
req.send();
					

规范

规范 状态 注释
XMLHttpRequest
The definition of 'overrideMimeType()' in that specification.
实时标准 WHATWG (Web 超文本应用程序技术工作组) 实时标准

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
overrideMimeType Chrome 1 Edge 12 Firefox Yes IE 11
11
5
Implemented via ActiveXObject
Opera Yes Safari 1.2 WebView Android Yes Chrome Android 18 Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android 1.0

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: