1

I've created a web service using Sinatra that returns JSON data.

For it to return JSON data, I've used:

class FooRunner
    def self.run!
        rates = {
             "data1" => price_money[2],
             "data2" => price_money[1],
             "data3" => price_money[3],
             "data4" => price_money[6],
             "data5" => price_money[5],
             "data6" => price_money[4]
        }
        rates.to_json
    end
end

and then as follows:

get '/'  do
  result = FooRunner.run!

  File.open('output.json','w') do |f| #just to keep a record
    f.write result
  end

  response['Access-Control-Allow-Origin'] = '*'
  content_type :json
  result
end

Now this works perfectly with both $.ajax or a simple $.getJSON function. However, I hit a snag for IE8 where the requirement is JSONP data.

I did try this:

$.ajax({ 
   url : 'url-of-sinatra-service',
   dataType : 'jsonp'
}).success( function(data){
   //some function
});

This returns data in the JSON format only (obviously) so I can't really proceed with the functionality. Is there a way for me to make this return JSONP or if I can convert this to a JSONP response?

Sir l33tname
  • 4,026
  • 6
  • 38
  • 49
Newtt
  • 6,050
  • 13
  • 68
  • 106
  • Take a look at http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonp especially http://stackoverflow.com/a/14523763/128421. – the Tin Man Feb 24 '14 at 22:25

0 Answers0