Advertisement
Guest User

Untitled

a guest
Feb 18th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. [ { cityPK: { name: 'Lodi', region: 'Lombardia' } },
  2. { cityPK: { name: 'Frosinone', region: 'Lazio' } },
  3. { cityPK: { name: 'Roma', region: 'Lazio' } },
  4. { cityPK: { name: 'Tivoli', region: 'Lazio' } } ]
  5.  
  6. var http = require('http');
  7. var request = require('request');
  8. var express = require('express');
  9. var bodyParser = require('body-parser');
  10. var app = express();
  11. app.use(bodyParser.urlencoded({extended:false}));
  12. app.use(bodyParser.json());
  13.  
  14. app.post('/login',function(req,res){
  15. console.log("sono nella post "+req.body.username);
  16. var uid = req.body.username;
  17. var upwd = req.body.password;
  18. res.setHeader('Content-Type', 'application/json');
  19. res.header("Access-Control-Allow-Origin", "*");
  20. res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  21. res.header("Access-Control-Allow-Credentials", true);
  22.  
  23.  
  24.  
  25. request({
  26. url: "http://localhost:8080/RestServiceAdmin/webresources/entities.city",
  27. method: "GET",
  28. json: true ,
  29. headers:[{'content-type': 'application/json'}]
  30. }, function (error, response, body){
  31. if(!error & response.statusCode === 200){
  32. res.json(body);
  33. }
  34. });
  35. });
  36. app.listen(9080,function(){
  37. console.log('Server running at http://127.0.0.1:9080/');
  38. });
  39.  
  40. var app = angular.module('myApp',[]);
  41. app.controller('myCtrl',function($scope,$http){
  42. $scope.check = function(data){
  43. var id = data.form.id;
  44. var pwd = data.form.password;
  45. console.log("utente è "+id+",password è "+pwd);
  46. var msg = {username: id,password: pwd};
  47. $http({
  48. url:'http://localhost:9080/login', //senza niente qui,metti * in app.post()
  49. method:"POST",
  50. data: $.param(msg),
  51. responseType: "application/json",
  52. headers: {'Content-Type': 'application/x-www-form-urlencoded',
  53. 'Accept': 'application/json'
  54. }})
  55. .then(function(response){
  56.  
  57. console.log("Server response "+response.data);
  58. });
  59. };
  60. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement