Skip to main content

Basic example of using .ajax() with JSONP?

Please could someone help me work out how to get started with JSONP?

Code:

$('document').ready(function() { var pm_url = 'http://twitter.com/status'; pm_url += '/user_timeline/stephenfry.json'; pm_url += '?count=10&callback=photos'; var photos = function (data) { alert(data); }; $.ajax({ url: pm_url, dataType: 'jsonp', jsonpCallback: 'photos', jsonp: false, }); });


Fiddle: http://jsfiddle.net/R7EPt/6/

Should produce an alert, as far as I can work out from the documentation: isn't (but isn't producing any errors either).

thanks.

ANSWER :

JSONP is really a simply trick to overcome XMLHttpRequest same domain policy. (As you know one cannot send AJAX (XMLHttpRequest) request to a different domain.)

So - instead of using XMLHttpRequest we have to use script HTMLl tags, the ones you usually use to load JS files, in order for JS to get data from another domain. Sounds weird?

Thing is - turns out script tags can be used in a fashion similar to XMLHttpRequest! Check this out:

script = document.createElement(”script”); script.type = “text/javascript”; script.src = “http://www.someWebApiServer.com/some-data”;


You will end up with a script segment that looks like this after it loads the data:

<script> {['some string 1', 'some data', 'whatever data']} </script>


However this is a bit inconvenient, because we have to fetch this array from script tag. So JSONP creators decided that this will work better (and it is):

script = document.createElement(”script”); script.type = “text/javascript”; script.src = “http://www.someWebApiServer.com/some-data?callback=my_callback”;


Notice *my_callback* function over there? So - when JSONP server receives your request and finds callback parameter - instead of returning plain JS array it'll return this:

my_callback({['some string 1', 'some data', 'whatever data']});


See where the profit is: now we get automatic callback (*my_callback*) that'll be triggered once we get the data. That's all there is to know about JSONP: it's a callback and script tags.

Comments

Popular posts from this blog

PIJAT PANGGILAN SEMARANG

via IFTTT

Perampokan dan Penyanderaan di Pondok Indah Jakarta

Jakarta - Polisi mengepung lokasi perampokan di Pondok Indah, Jakarta Selatan. Mereka memberi waktu perampok untuk menyerah. Berkali-kali, pengumuman peringatan diteriakkan. "Mohon memberi respons, mohon memberi respons. Kami beri waktu 3 menit. Waktu terus berjalan, percuma melakukan perlawanan," kata polisi melalui pengeras suara. Lokasi perampokan terletak di Bukit Hijau XI, No 17, Pondok Indah. Hingga saat ini, polisi terus meneriakkan peringatan tersebut. Saat ini, puluhan polisi bersiaga di lokasi. Garis polisi terpasang. Warga dilarang mendekat. Menurut informasi, 2 pelaku mengenakan topeng dan menyandera 4 korban. Rumah yang dirampok berlantai 3. Tidak diketahui aktivitas apa di rumah tersebut. sumber : http://news.detik.com/berita/3290275/perampokan-di-pondok-indah-polisi-ke-pelaku-quotmohon-merespons-percuma-melawanquot?_ga=1.51184238.636799632.1472747217

video porno threesome ulama bogor , Astagfirullah

Download 3gp full video porno ulama bogor menjadi topik hangat di meta keyword pencarian google setelah sebelumnya telah ditangkap oleh aparat setempat SS yang seorang pengurus DKM , BAZIZ dan juga pengurus serta ulama di MUI bogor setelah dalam video berdurasi 6 menit disinyalir SS merupakan sosok pria yang melakukan hubungan suami istri dengan 2 wanita yang juga diduga merupakan tenaga guru honorer di bogor Video mesum ulama bogor tersebut tak urung membuat masyarakat bogor heboh dan mengundang kecaman dari para pengurus MUI bogor lainnya, atas kasus tersebut polisi diminta untuk segera mengusut tuntas permasalahan ini termasuk juga mengusut pelaku penyebaran video porno yang tidak mendidik tersebut http://lintaspromosi.blogspot.com