Created
March 10, 2014 17:20
-
-
Save atilacamurca/9469588 to your computer and use it in GitHub Desktop.
Cross Site Access via JSONP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Api extends HttpServlet { | |
protected void responder(JSONObject resultado, HttpServletResponse response, String callback) { | |
try { | |
response.setContentType("text/javascript;charset=utf-8"); | |
response.setHeader("Access-Control-Allow-Headers", "Content-Type, x-xsrf-token"); | |
PrintWriter out = response.getWriter(); | |
String saida = callback + "(" + resultado + ");"; | |
out.print(saida); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('pegasusMobileApp') | |
.controller('ClienteCtrl', function ($scope, clientesFactory, $location) { | |
// termo da busca | |
$scope.termo = ""; | |
$scope.clientes = clientesFactory.query({ | |
acao: 'index', | |
termo: $scope.termo | |
}); | |
console.log($scope.clientes); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
angular.module('pegasusMobileApp') | |
.factory('clientesFactory', function ($resource) { | |
return $resource('http://localhost:8084/pegasus/api/cliente/', { | |
callback: 'JSON_CALLBACK' | |
}, { | |
query: { | |
method: 'JSONP' | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment