2011/6/15 patrick <[email protected]>:
> A quick simple question... given the following js code
>
> if (window.XMLHttpRequest){
> var xhr = new XMLHttpRequest();
> } else {
> ... IE stuff....
> }
>
> var params = "key=value& etc...";
>
> xhr.open("POST", formUrl, true);
> xhr.setRequestHeader("Content-Type", "application/x-www-form-
> urlencoded");
> xhr.setRequestHeader("Content-length", params.length);
> xhr.setRequestHeader("Connection", "close");
> xhr.send(params);
You need to format the data to be sent to a POST string, aka a `&`
separated string, equal to standard query string. The value and key
pairs should be both escaped with encodeURIComponent. Example:
function params(data) {
var m, params = [];
for (m in data) {
if (data.hasOwnProperty(m)) {
params.push(encodeURIComponent(m) + '=' + encodeURIComponent(data[m]));
}
}
return params;
}
xhr.send(params({key1: 'value', key2: value}).join('&'));
--
Poetro
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]