SoFunction
Updated on 2025-03-10

Javascript submits data instance using post method

This article describes the method of Javascript using post method to submit data. Share it for your reference. The details are as follows:

When submitting data using JS, you can call this method to implement the post method submission.

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

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