Spring JSON-P with Jackson

This commit is contained in:
MafaldaLandeiro 2016-07-27 20:55:04 +01:00
parent 9b30521a3f
commit a384872870
2 changed files with 110 additions and 45 deletions

View File

@ -1,27 +1,70 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="ISO-8859-1"> <meta charset="ISO-8859-1">
<title>Company Data</title> <title>Company Data</title>
<script> <script src="https://code.jquery.com/jquery-3.1.0.js"
function getCompanyData(data) { integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk="
document.write("<b>ID:</b> "+data.id+"<br/>"); crossorigin="anonymous"></script>
document.write("<b>NAME:</b> "+data.name+"<br/>"); <script>
document.write("<br/>"); $(document).ready(function(){
} $('#ResponseBody-button').click(function() {
</script> $.ajax({
</head> url: 'http://localhost:8080/spring-mvc-java/companyResponseBody?callback=getCompanyData',
<body> data: {
<!--Using @ResponseBody --> format: 'json'
<script },
src="http://localhost:8080/spring-mvc-java/companyResponseBody?callback=getCompanyData" type: 'GET',
type="application/javascript"> </script> jsonpCallback:'getCompanyData',
dataType: 'jsonp',
<!--Using ResponseEntity --> error: function() {
<script $('#infoResponseBody').html('<p>An error has occurred</p>');
src="http://localhost:8080/spring-mvc-java/companyResponseEntity?callback=getCompanyData" },
type="application/javascript"> </script> success: function(data) {
console.log("sucess");
</body> }
</html> });
});
$('#ResponseEntity-button').click(function() {
console.log("ResponseEntity");
$.ajax({
url: 'http://localhost:8080/spring-mvc-java/companyResponseEntity?callback=getCompanyData',
data: {
format: 'json'
},
type: 'GET',
jsonpCallback:'getCompanyData',
dataType: 'jsonp',
error: function() {
$('#infoResponseEntity').html('<p>An error has occurred</p>');
},
success: function(data) {
console.log("sucess");
}
});
});
});
function getCompanyData(data) {
document.write("<b>ID:</b> "+data.id+"<br/>");
document.write("<b>NAME:</b> "+data.name+"<br/>");
document.write("<br/>");
}
</script>
</head>
<body>
<!-- Using REST URL-->
<button id="REST-button">Test REST JSON-P!</button>
<div id="infoREST"></div>
<!--Using @ResponseBody -->
<button id="ResponseBody-button">Test ResponseBody JSON-P!</button>
<div id="infoResponseBody"></div>
<!--Using ResponseEntity -->
<button id="ResponseEntity-button">Test ResponseEntity JSON-P!</button>
<div id="ResponseEntity"></div>
</body>
</html>

View File

@ -1,22 +1,44 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="ISO-8859-1"> <meta charset="ISO-8859-1">
<title>Company Data</title> <title>Company Data</title>
<script> <script src="https://code.jquery.com/jquery-3.1.0.js"
function getCompanyData(data) { integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk="
document.write("<b>ID:</b> "+data.id+"<br/>"); crossorigin="anonymous"></script>
document.write("<b>NAME:</b> "+data.name+"<br/>"); <script>
document.write("<br/>"); $(document).ready(function(){
} $('#REST-button').click(function() {
</script> $.ajax({
</head> url: 'http://localhost:8080/spring-rest/companyRest?callback=getCompanyData',
<body> data: {
<!-- Using REST URL--> format: 'json'
<script },
src="http://localhost:8080/spring-rest/companyRest?callback=getCompanyData" type: 'GET',
type="application/javascript"> </script> jsonpCallback:'getCompanyData',
dataType: 'jsonp',
</body> error: function() {
</html> $('#infoREST').html('<p>An error has occurred</p>');
},
success: function(data) {
console.log("sucess");
}
});
});
});
function getCompanyData(data) {
document.write("<b>ID:</b> "+data.id+"<br/>");
document.write("<b>NAME:</b> "+data.name+"<br/>");
document.write("<br/>");
}
</script>
</head>
<body>
<!-- Using REST URL-->
<button id="REST-button">Test REST JSON-P!</button>
<div id="infoREST"></div>
</body>
</html>