Javascript使用post方法提交数据

http://www.oschina.net/code/snippet_28910_5253?_t_t_t=0.268690651472958


var jsPost = function (action, values) {
     var id = Math.random();
     document.write( '<form id="post' + id + '" name="post' + id + '" action="' + action + '" method="post">' );
     for ( var key in values) {
         document.write( '<input type="hidden" name="' + key + '" value="' + values[key] + '" />' );
     }
     document.write( '</form>' );   
     document.getElementById( 'post' + id).submit();
}
 
jsPost( 'b.html' , {
     'username' : 'zhangsan' ,
     'password' : '123'
});

你可能感兴趣的:(JavaScript)