支持 javascript 中的 POST 数据

Support for POST data in javascript

是否有任何库支持为 XMLHTTPRequest 创建 post 数据 在 javascript。 考虑发送 post 数据如下。

var http = new XMLHttpRequest();
var url = "get_data.php";
var params = "lorem=ipsum&name=binny";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
http.send(params);

我想知道是否有更好的方法来组合表单中的数据(而不是字符串连接)。 var params = "lorem=ipsum&name=binny";

查看qwest简单高效重量仅8.5K

JQuery.param()呢?参见 http://api.jquery.com/jquery.param/

var params = { 
   lorem:ipsum, 
   name:binny 
};
var str = jQuery.param( params );
// str = lorem=ipsum&name=binny

另一个,这一次,香草 JavaScript 解决方案将来自 this post