According to its documentation, GM_xmlhttpRequest
should be able to take a data
parameter as part of its argument.
However, I can't seem to get it to work.
I have a simple server that echoes the parameters given to it:
require 'sinatra'
require 'json'
get '/' do
JSON.dump params
end
post '/' do
JSON.dump params
end
And a simple greasemonkey script that just tries to POST some data to the server. It tries to pass data as query parameters in the URL and as postdata:
// ==UserScript==
// @name PostDataTest
// @namespace Test
// @description Simple test of GM_xmlhttpRequest's data parameter
// @include http://localhost:4567/
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @grant metadata
// @grant GM_xmlhttpRequest
// ==/UserScript==
var url = '/?q0=0&q1=1';
var data = 'd0=0&d1=1'
GM_xmlhttpRequest({ method: 'POST', url: url, data: data, onload: function(r){
console.log('gm:' + r.responseText);
}});
$.post(url, data, function(d,s,r){
console.log('jq:' + r.responseText);
});
When I POST postdata using jQuery, it works fine, but any postdata I POST using GM_xmlhttpRequest
is ignored:
jq:{"q0":"0","q1":"1","d0":"0","d1":"1"}
gm:{"q0":"0","q1":"1"}
This leads me to believe that GM_xmlhttpRequest
isn't actually using the data
parameter I'm giving it. (I'm not sure b/c I can't monitor GM_xmlhttpRequest
's network activity in Firebug).
What's going on here? Did I screw something up? Did the API shift? How can I use GM_xmlhttpRequest
to post data without packing it into the URL?