Home > Web Front-end > JS Tutorial > body text

Javascript uses post method to submit data instance_javascript skills

WBOY
Release: 2016-05-16 15:47:49
Original
1312 people have browsed it

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'
});

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template