Karl Gustav Røksund
Accenture
#acntech
<script>function afunction(json){var myObj = JSON.parse(json)console.log(myObj.theJson) //"content" is printed to the console}</script>
<script src="http://otherWebServer.com/some-content.jsonp"></script>
aFunction('{"theJson": "content"}')
$.ajax({
url: "http://otherWebServer.com/some-content.jsonp",
jsonp: "aFunction",
dataType: "jsonp",
success: function( json ) {
var myObj = JSON.parse( json )
console.log(myObj.theJson) //"content" is printed to the console
}
});
$.ajax({
url: "http://otherWebServer.com/getSomeJson?callback=?",
dataType: "jsonp",
success: function( json ) {
var myObj = JSON.parse( json )
console.log(myObj.theJson) //"content" is printed to the console
}
});
Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: http://example.com:8080
<!-- Get stuff from the other server just as easily as your own --><html><body><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<button onclick="$.get('http://updates.html5rocks.com', function(text){alert(text)})">
DON'T PUSH THIS BUTTON</button>
</body></html>