Advertisement
Guest User

Untitled

a guest
Apr 1st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. $.ajax({
  2. method: "POST",
  3. contentType: 'application/json',
  4. dataType: 'json',
  5. url: "localhost:8000/test",
  6. data: JSON.stringify({user:"john", pass:"123"}),
  7. error: function () {
  8. alert('error');
  9. },
  10. success: function (data) {
  11. alert('success');
  12. }
  13. });
  14.  
  15. var express = require('express');
  16. var app = express();
  17. var bodyParser = require('body-parser');
  18.  
  19. app.use(bodyParser.json());
  20. app.use(bodyParser.urlencoded({ extended: true }));
  21.  
  22. app.post('/login', function (req, res) {
  23. var user = req.body.user;
  24. var password = req.body.pass;
  25. if(user == 'john' && password == '123') {
  26. res.status(200);
  27. } else {
  28. res.status(401);
  29. }
  30. });
  31.  
  32. app.listen(8000, function () {
  33. console.log('Example app listening on port 8000!');
  34. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement