0

can somebody please explain the function of jsonp=? in this Ajax GET request?

$(document).ready(function(){

  $.ajax({
    url: "https://api.forismatic.com/api/1.0/?",
    data: "method=getQuote&format=jsonp&lang=en&jsonp=?",
    success: function(data){
      $(".message").text(data.quoteText);
    },
    dataType: "jsonp"
  });
});

Here's a link of this in action: https://codepen.io/ltcMatt/pen/VWeoMW.

Thanks in advance.

Cheers

ErnieandBert
  • 91
  • 1
  • 1
  • 8
  • 1
    checkout https://stackoverflow.com/q/3839966/6611700 – riyaz-ali Jun 10 '17 at 17:28
  • thx @riyaz-ali. So jsonp=? is basically an equivalent to callback=?, right? – ErnieandBert Jun 10 '17 at 17:34
  • yess! if you inspect the _normal_ json response of the API you will possibly find a json object (or an array) which you can then parse using JSON.parse but if you inspect the response with _JSONP_ you will actually see that the api wraps the json object into callback with parenthesis efectively turning it into a function call which your browser will parse as any normal JS function call and invoke the function – riyaz-ali Jun 10 '17 at 17:55

0 Answers0