Has anyone posted data with GM_xmlhttprequest using method POST??
I'm not able to pass data with this code, the web is loaded but no data
is passed, I've sniffed the transmission...
any idea, could it be a greasemonkey bug??
var submit = function(params) {
GM_xmlhttpRequest ( {
method : "POST",
url : url,
headers : {
'content-type': 'application/x-www-form-urlencoded',
'content-length': params.length,
'User-agent': 'Mozilla/4.0 (compatible)',
'Accept': '*'
},
data : params,
onload : function(details)
{
if (details.readyState == 4) {
if (details.status != 200) {
return;
}
alert(details.responseText);
}
}
} );
}
Am I missing something, or is 'url' undefined? It seems like it should
be a parameter to your function or something, like:
var submit = function(url, params) {
I don't know why this would happen, though: "the web is loaded but no
data is passed", because it seems like the opposite is being set up...
creating a request that has no URL but does have parameters.
--
-dave
geek blog: http://spugbrap.blogspot.com
personal blog: http://spugbrap-personal.blogspot.com
new (consolidated) blog: http://spugbrap.wordpress.com
family website: http://www.oatmealcookies.org
bookmarks: http://del.icio.us/spugbrap
Nobody has ever post data with gm_xmlhttprequest??
function send(data) {
GM_xmlhttpRequest({
method: 'POST',
url: mysubmit,
headers: {
'Content-type': 'multipart/form-data; boundary=shapecms',
},
data: data,
onload: function(responseDetails) {
var ok = '200';
if(responseDetails.status == ok) {
}
else {
GM_log('error message:'+responseDetails.responseText);
}
GM_log(responseDetails.responseText);
}
}) };
function postdata() {
var newseparator = '--'+separator;
var submitFormInput = xpath("//form[@id='shapecms_web2']//input");
var submitFormTextarea =
xpath("//form[@id='shapecms_web2']//textarea");
var postdata = postInput(submitFormInput, newseparator);
if(postdata != "") postdata += '\r\n'+
postInput(submitFormTextarea, newseparator);
else postdata += postInput(submitFormTextarea, newseparator);
if(postdata) postdata +='\r\n'+newseparator+'--'
return(postdata);
}
function postInput(form, separator) {
var postdata ="";
var newline = '\r\n';
for(var i = 0; i < form.snapshotLength; i++) {
var field = form.snapshotItem(i);
// GM_log('Field:'+field.tagName);
// GM_log(field.name + "=" + field.value);
if(postdata !="") postdata += newline;
var tosend = encodeURIComponent(field.value);
postdata += separator+newline+'Content-Disposition:
form-data; name="'+field.name+'"'+newline+newline+tosend;
}
return(postdata);
}
[snip]
Hans
On 10/26/06, Jonas Lundberg <my.name...@gmail.com> wrote:
> Here is an example using multipart-form-data for you (not exactly what
> you wanted, but quite close maybe?) . The data is formatted using the
[snip]
Hans
>
- I have removed on the header 'content-length': params.length.
- The params are global so I also have removed the param argument.
Thanks anyway... ;)