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?