Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. function submitPOST(elementId, api, callback) {
  2.  
  3. let input = document.getElementById(elementId).getElementsByTagName("input");
  4.  
  5. let body = {};
  6. for (let i = 0; i < input.length; i++) {
  7. body[input[i].name] = input[i].value;
  8. }
  9.  
  10. call('POST', api, body, callback);
  11.  
  12. xmlHttp.onload = function () {
  13. if (xmlHttp.status==200){
  14. callback(xmlHttp.response);
  15. }else{
  16. console.log(xmlHttp.response);
  17. }
  18. };
  19. xmlHttp.open(method, domainName+"/api/"+api, true); // true for asynchronous
  20. xmlHttp.setRequestHeader("Content-Type", "application/json");
  21. xmlHttp.send(JSON.stringify(body));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement