If you read wikipedia definition:
JSONP or “JSON with padding” is a communication technique used in JavaScript. It provides a method to request data from a server in a different domain, something prohibited by typical web browsers because of the same origin policy.
But let’s dig it right away with an example. I will use J50Npi standalone javascript library for that.
Step by Step Beginner’s Sample
Say you want to client-side print the user’s Country IP using some external JSONP free service.
You can test that solution from your browser right now:
1. Open your Browser
2. Open a non javascript intensive page; e.g. Roberto’s blog
3. Open the console by pressing F12 or whatever key your browser use. You may need to select tab ‘Console’ (tested on Chrome and Internet Explorer 10)
4. Paste the below code (within the console)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
You should see an alert saying your current (ip based location) country name after half a second or so.