Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. fetch('https://mywebsite.com/endpoint/', {
  2. method: 'POST',
  3. headers: {
  4. 'Accept': 'application/json',
  5. 'Content-Type': 'application/json',
  6. },
  7. body: JSON.stringify({
  8. firstParam: 'yourValue',
  9. secondParam: 'yourOtherValue',
  10. })
  11. })
  12.  
  13. var request = new XMLHttpRequest();
  14. request.open('POST', '/my/url', true);
  15. request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
  16. request.send(data);
  17.  
  18. $.ajax({
  19. type: 'POST',
  20. url: '/some/url',
  21. data: data
  22. })
  23. .done(function(result) {
  24. this.clearForm();
  25. this.setState({result:result});
  26. }.bind(this)
  27. .fail(function(jqXhr) {
  28. console.log('failed to register');
  29. });
  30.  
  31. npm install superagent --save
  32.  
  33. import request from "../../node_modules/superagent/superagent";
  34.  
  35. request
  36. .post('http://localhost/userLogin')
  37. .set('Content-Type', 'application/x-www-form-urlencoded')
  38. .send({ username: "username", password: "password" })
  39. .end(function(err, res){
  40. console.log(res.text);
  41. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement