I have this code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$.getJSON('http://example.com/api/get_cats', function(fbResults) {
document.write(fbResults.cats[0].title);
});
});
</script>
How can I change this code:
<script>
$(document).ready(function() {
$.getJSON('http://example.com/api/get_cats', function(fbResults) {
document.write(fbResults.cats[0].title);
});
});
</script>
for it to work as JSONP ... Is this totally different?
<script>request. The response must have the data wrapped in a function call, likemy_func({"foo":"bar"}). Then when the script arrives, assuming there's a function namedmy_func, that function is invoked passing the data into it. Some servers let you specify the function name, and they'll return the JSONP response, but this behavior must be established on the server.