Spring JSON-P with Jackson
This commit is contained in:
parent
9b30521a3f
commit
a384872870
|
@ -1,27 +1,70 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="ISO-8859-1">
|
||||
<title>Company Data</title>
|
||||
<script>
|
||||
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 @ResponseBody -->
|
||||
<script
|
||||
src="http://localhost:8080/spring-mvc-java/companyResponseBody?callback=getCompanyData"
|
||||
type="application/javascript"> </script>
|
||||
|
||||
<!--Using ResponseEntity -->
|
||||
<script
|
||||
src="http://localhost:8080/spring-mvc-java/companyResponseEntity?callback=getCompanyData"
|
||||
type="application/javascript"> </script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<head>
|
||||
<meta charset="ISO-8859-1">
|
||||
<title>Company Data</title>
|
||||
<script src="https://code.jquery.com/jquery-3.1.0.js"
|
||||
integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk="
|
||||
crossorigin="anonymous"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#ResponseBody-button').click(function() {
|
||||
$.ajax({
|
||||
url: 'http://localhost:8080/spring-mvc-java/companyResponseBody?callback=getCompanyData',
|
||||
data: {
|
||||
format: 'json'
|
||||
},
|
||||
type: 'GET',
|
||||
jsonpCallback:'getCompanyData',
|
||||
dataType: 'jsonp',
|
||||
error: function() {
|
||||
$('#infoResponseBody').html('<p>An error has occurred</p>');
|
||||
},
|
||||
success: function(data) {
|
||||
console.log("sucess");
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#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>
|
|
@ -1,22 +1,44 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="ISO-8859-1">
|
||||
<title>Company Data</title>
|
||||
<script>
|
||||
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-->
|
||||
<script
|
||||
src="http://localhost:8080/spring-rest/companyRest?callback=getCompanyData"
|
||||
type="application/javascript"> </script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<head>
|
||||
<meta charset="ISO-8859-1">
|
||||
<title>Company Data</title>
|
||||
<script src="https://code.jquery.com/jquery-3.1.0.js"
|
||||
integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk="
|
||||
crossorigin="anonymous"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#REST-button').click(function() {
|
||||
$.ajax({
|
||||
url: 'http://localhost:8080/spring-rest/companyRest?callback=getCompanyData',
|
||||
data: {
|
||||
format: 'json'
|
||||
},
|
||||
type: 'GET',
|
||||
jsonpCallback:'getCompanyData',
|
||||
dataType: 'jsonp',
|
||||
error: function() {
|
||||
$('#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>
|
Loading…
Reference in New Issue