1

I was creating social buttons and had a problem with Twitter, does not work with AJAX by "some restrictions". I searched the Web and found examples that work, but with jQuery.

I made a testing, here it is:

`http://jsfiddle.net/fqyk1a4p/2/`

I wonder what the pure Javascript version jQuery.getJSON, please.

Thank you.

  • Wonder no longer ~ https://github.com/jquery/jquery/blob/2.1.4/src/ajax.js#L757 – Phil Oct 23 '15 at 03:14
  • Here is the direct link, was /3/ in jsfiddle, thanks [link]http://jsfiddle.net/fqyk1a4p/3/ – Carlos Duran Oct 23 '15 at 03:15
  • 3
    $.getJSON (and $.ajax) will also do jsonp requests that aren't XMLHttpRequest – charlietfl Oct 23 '15 at 03:16
  • Yup, as @charlietfl points out, the `callback=?` query parameter in the Twitter URI tell jQuery to perform a JSONP request to get around the cross-origin restriction. See https://api.jquery.com/jQuery.getJSON/#jsonp – Phil Oct 23 '15 at 03:17
  • Oh... jQuery.getJSON returns to jQuery.get( url, data, callback, "json" )... which is equal to "get"? – Carlos Duran Oct 23 '15 at 03:20
  • 2
    @Phil not sure if you ever saw this [jQuery source reader](http://james.padolsey.com/jquery/#v=1.11.2&fn=jQuery.getJSON) – charlietfl Oct 23 '15 at 03:21
  • @charlietfl that's cool. Should help OP on their journey down the rabbit hole – Phil Oct 23 '15 at 03:22
  • @charlietfl, are you a robot? I really don't understand how can you help people as much hours as you do! Go to sleep please we still need you – Adib Aroui Oct 23 '15 at 03:26
  • @whitelettersinblankpapers nah...I'm just old and wet myself when I sleep – charlietfl Oct 23 '15 at 03:27
  • @charlietfl, I didn't fully get you but I just wanted heartfully to say it, even in this inapproprite place, you really help too much and I was reading your comment last night before sleeping... Now I start my day by sending you my thanks and wishes. hope u don't misunderstand – Adib Aroui Oct 23 '15 at 03:30
  • 1
    @whitelettersinblankpapers all's good! appreciate the thought .. was joking a bit but I am old too – charlietfl Oct 23 '15 at 03:32
  • @charlietfl, If that is the meaning of being old, I hope all the world becomes old. the truth is, we useless people are the old one, till we become useful and younger.(Carlos sorry sir) – Adib Aroui Oct 23 '15 at 03:37
  • I think you have the solution but do not quite understand. How to be a function pure javacript act as the "jQuery.getJSON"? Where I put the "callback"? :( – Carlos Duran Oct 23 '15 at 03:37
  • in a way, `request.onreadystatechange` is the callback. but you can do more. here is a nice example: http://stackoverflow.com/questions/5485495/how-can-i-take-advantage-of-callback-functions-for-asynchronous-xmlhttprequest – wazz Oct 23 '15 at 05:15
  • another example at the bottom of the page: http://www.w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp – wazz Oct 23 '15 at 05:19
  • I did this http://jsfiddle.net/fqyk1a4p/4/ but no works. But I found another way, the "JSONP" you mentioned. I did not know, it worked, thanks! Greetings from Peru. (Lo aprendí aquí http://davidwalsh.name/twitter-facebook-jsonp) – Carlos Duran Oct 23 '15 at 12:59

0 Answers0