Created
December 2, 2015 22:27
-
-
Save samueleresca/72fa11736ab455ca5694 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<title>JSON - JSONP tests</title> | |
<!--Include jquery--> | |
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> | |
<script type="text/javascript"> | |
$(function(){ | |
//DEF response | |
var data = {}; | |
data.title = "title"; | |
data.message = "message"; | |
//Handler on JSONP anchor click | |
$('#select_link_JSONP').click(function(e){ | |
e.preventDefault(); | |
//LOG | |
console.log('select_link_JSONP clicked'); | |
//JSONP request | |
$.ajax({ | |
dataType: 'jsonp', | |
data: JSON.stringify(data), | |
jsonp: 'callback', | |
url: 'http://localhost:3000/endpointJSONP?callback=?', | |
success: function(data) { | |
//LOG | |
console.log('success'); | |
console.log(JSON.stringify(data)); | |
} | |
}); | |
}); | |
//Handler on JSON anchor click | |
$('#select_link_JSON').click(function(e){ | |
e.preventDefault(); | |
//LOG | |
console.log('select_link_JSON clicked'); | |
//JSON request | |
$.ajax({ | |
data: JSON.stringify(data), | |
contentType: 'application/json', | |
url: 'http://localhost:3000/endpointJSON', | |
success: function(data) { | |
console.log('success'); | |
console.log(JSON.stringify(data)); | |
} | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="select_div_JSONP"><a href="#" id="select_link_JSONP">Test JSONP</a></div> | |
<div id="select_div_JSON"><a href="#" id="select_link_JSON">Test JSON</a></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment