0

Am trying to get the $.getJSON call back to work for an api that is returning json instead of jsonp data. How can alter this to work.

$.getJSON("http://url&callback=?", function(response){ alert("hi");  });

2 Answers2

2

Recently i worked on similar kind of issue to get the twitter count of URL using twitter API Call which generates JSON response.

Look below snippet for reference

<script type="text/javascript">
 $(document).ready(function () {
     var url = "http://www.google.com/"; //test url 
     $.getJSON('http://urls.api.twitter.com/1/urls/count.json?url=' + url + '&callback=?', function (data) {
                   console.log(data);
                });
});
</script>

I hope it will be useful for you too :)

sweetu
  • 21
  • 1
0

JSONP is not a data type. If you would like to learn more about JSONP please read this SO post called "What is JSONP all about?"

You can actually use $.ajax or $.get (or any jQuery ajax methods for that matter) when making ajax requests on an OS/400 but if you are calling RPGLE PGMs from a different port than the actual HTTP SERVER/Domain then you must provide the ?callback=? method which let's the javascript engine know its JSONP (I believe). JSONP is actually a javascript function/wrapper which allows the data to be passed to the client without any reservations. If you are using an API such as twitter where you are performing cross-domain call its better that you know the provider is SECURE.

I was getting a 500 Internal Server Error by performing a GET when actually doing a POST so I investigated the proper way to make Ajax requests.

Community
  • 1
  • 1
yardpenalty.com
  • 1,244
  • 2
  • 17
  • 32