Home >Web Front-end >JS Tutorial >Javascript uses post method to submit data instance_javascript skills
The example in this article describes how Javascript uses the post method to submit data. Share it with everyone for your reference. The details are as follows:
When using JS to submit data, you can call this method to implement post submission.
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' });
I hope this article will be helpful to everyone’s JavaScript programming design.