Sinatra, JavaScript Cross-Domain Requests JSON
Posted
by pex
on Stack Overflow
See other posts from Stack Overflow
or by pex
Published on 2010-03-24T19:26:39Z
Indexed on
2010/03/24
19:33 UTC
Read the original article
Hit count: 229
I run a REST-API build on top of Sinatra. Now I want to write a jQuery Script that fetches data from the API.
Sinatra is told to response with JSON
before do
content_type :json
end
A simple Route looks like
get '/posts' do
Post.find.to_json
end
My jQuery script is a simple ajax-call
$.ajax({
type: 'get',
url: 'http://api.com/posts',
dataType: 'json',
success: function(data) {
// do something
}
})
Actually everything works fine as long as both runs on the same IP, API and requesting JS. I already tried to play around with JSONP for Rack without any positive results, though. Probably I just need a hint how to proceed.
© Stack Overflow or respective owner