GM.xmlHttpRequest: Difference between revisions
m →Notes |
m →Notes |
||
Line 39: | Line 39: | ||
= Notes = | = Notes = | ||
Note that some attributes may not actually work through GM_xmlhttpRequest. The Referer header atom is one that is known to be recognized but | Note that some attributes may not actually work through GM_xmlhttpRequest. The Referer header atom is one that is known to be recognized but appears to be content filtered by the browser. This may be due to security restrictions to keep user scripts from doing unsafe things. References here: | ||
* http://groups.google.com/group/greasemonkey-dev/browse_thread/thread/77c94cc17c6b2669 | * http://groups.google.com/group/greasemonkey-dev/browse_thread/thread/77c94cc17c6b2669 | ||
* http://userscripts.org/forums/1/topics/1302?page=1#posts-5312 | * http://userscripts.org/forums/1/topics/1302?page=1#posts-5312 |
Revision as of 21:17, 4 December 2007
Syntax
GM_xmlhttpRequest( details )
Description
This API provides access to the chrome-privileged XMLHttpRequest object. This means that it is possible to issue requests to domains other than that of the current page.
The details parameter is an object having the following properties: method, url, headers, onload, onreadystatechange, onerror, data, overrideMimeType. All fields are optional except method and url. The headers field is an object which should contain the name-value pairs of the headers to send, for instance {"User-Agent":"Mozilla"}. The onload, onreadystatechange, and onerror parameters are callback functions which are called when the corresponding events occur.
Callback functions should accept a single object parameter having the following properties: responseText, status, statusText, readyState, and responseHeaders.
The responseHeaders is the string representation of response headers returned by XMLHTTPRequest.getAllResponseHeaders()
.
Examples
GM_xmlhttpRequest({ method:"GET", url:"http://youngpup.net/", headers:{ "User-Agent":"monkeyagent", // Recommend using window.location.href when possible "Accept":"text/monkey,text/xml" }, onload:function(details) { alert([ details.status, details.statusText, details.readyState, details.responseHeaders, details.responseText ].join("\n")); } });
Notes
Note that some attributes may not actually work through GM_xmlhttpRequest. The Referer header atom is one that is known to be recognized but appears to be content filtered by the browser. This may be due to security restrictions to keep user scripts from doing unsafe things. References here:
- http://groups.google.com/group/greasemonkey-dev/browse_thread/thread/77c94cc17c6b2669
- http://userscripts.org/forums/1/topics/1302?page=1#posts-5312
Some users have reported problems with international character sets. See these mailing list threads
- http://www.mozdev.org/pipermail/greasemonkey/2006-June/008785.html
- http://www.mozdev.org/pipermail/greasemonkey/2006-April/008064.html
The overrideMimeType
parameter became available in version 0.6.8.