Home  >  Article  >  Web Front-end  >  Javascript uses post method to submit data instance_javascript skills

Javascript uses post method to submit data instance_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:47:491311browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn