I am currently trying to navigate to send a GET request to a URL, parse what is returned into a JSON and use it in my Javascript.
At the moment, I am using dummy data like so :
data = [
{
:id=> "1",
:rev=> "1.0",
:text=> "This is a test"
}]
And this works perfectly in my code :
<ul>
<% data.each do |item| %>
<li>
...
Now I have a webpage which returns the data after a GET request in this form :
{"alerts":[{"_id":"1","_rev":"1.0","text":"This is a test"}]}
when I call this, however, I am getting a connection refused error, here is my code :
# require 'open-uri'
# content = open("http://mywebsite.returnsDataAbove.com").read
and
# require 'net/http'
# require 'json'
# url = URI.parse('http://mywebsite.returnsDataAbove.com')
# req = Net::HTTP::Get.new(url.to_s)
# res = Net::HTTP.start(url.host, url.port) {|http|
# http.request(req)
# }
# puts res.body
# hash = JSON.parse res.body
# puts hash
what have I done incorrectly here?
Thanks a lot.