See the documents for GM_xmlhttpRequest()
. data
takes only a string.
If you try to send non-string data to data
, you will get an error like:
Component does not have requested interface
(113 out of range 67)
So, you must encode data into an appropriate string. Also, you will need to send the appropriate Content-Type
header. The two main types/methods are:
application/x-www-form-urlencoded
Andapplication/json
Encoding and sending the data looks like this for the two methods:
Form-encoded data:
GM_xmlhttpRequest ( {
method: "POST",
url: "www.prova.it",
data: "parametro=" + encodeURIComponent (parametro),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function (response) {
console.log(response.responseText);
},
onerror: function(reponse) {
//alert('error');
console.log("error: ", reponse);
}
} );
JSON serialized data:
GM_xmlhttpRequest ( {
method: "POST",
url: "www.prova.it",
data: JSON.stringify ( {parametro:parametro} ),
headers: {
"Content-Type": "application/json"
},
onload: function (response) {
console.log(response.responseText);
},
onerror: function(reponse) {
//alert('error');
console.log("error: ", reponse);
}
} );