I have a piece of Javascr开发者_如何学Cipt code that uses an XHR to POST data to a URL, but it uses FormData, which is not supported in earlier versions of Chrome. This is very handy, but I want it to be backwards-compatible, so what is the best way to rewrite the makeFormData method to return the data ready to send?
The offending code is here:
http://bitbucket.org/piranha/historious.crx/src/tip/background.html#cl-86
Thank you!
EDIT: You can override FormData
to create an encoded POST string like this...
function FormData() {
var obj = {}
this.append = function(key, val) {
obj[key] = val;
}
this.toString = function() {
var s = "";
for(var k in obj) {
s += ((s.length == 0) ? "?" : "&");
s += k;
s += "=";
s += encodeURIComponent(obj[k]); // might want to use escape() instead
}
return s;
}
}
精彩评论