Created
September 10, 2012 17:28
-
-
Save bjhaid/3692321 to your computer and use it in GitHub Desktop.
Trying to make an ajax request from a bare html to a rails 3 app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Controller | |
class MongobrokersController < ApplicationController | |
skip_before_filter :verify_authenticity_token | |
#dont forget to change 56800 to 3600 | |
def air_hour | |
@air = Mongobroker.where(status: "up", node: "air", timestamp: (Time.now - 86400)..Time.now) | |
render :json => @air | |
end | |
def ema_hour | |
@ema = Mongobroker.where(status: "up", node: "ema", timestamp: (Time.now - 86400)..Time.now) | |
render :json => @ema | |
end | |
def broker_hour | |
@broker = [] | |
Mongobroker.where(status: "up", node: "broker", timestamp: (Time.now - 86400)..Time.now).each { |x| @broker << x.value } | |
render :json => @broker | |
end | |
end | |
html | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<link class="include" rel="stylesheet" type="text/css" href="../jquery.jqplot.min.css" /> | |
<link rel="stylesheet" type="text/css" href="examples.min.css" /> | |
<link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shCoreDefault.min.css" /> | |
<link type="text/css" rel="stylesheet" href="syntaxhighlighter/styles/shThemejqPlot.min.css" /> | |
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="../excanvas.js"></script><![endif]--> | |
<script class="include" type="text/javascript" src="../jquery.js"></script> | |
</head> | |
<body> | |
<div id="chart2" style="height:300px; width:500px;"></div> | |
<script class="code" type="text/javascript"> | |
$(document).ready(function(){ | |
var ayo = $.ajax({ | |
type: "GET", | |
dataType: "jsonp", | |
url: "http://0.0.0.0:3000/mongobrokers/broker_hour", | |
success:function(data){ | |
alert("success"); | |
}, | |
xhrFields: { | |
withCredentials: true | |
}, | |
error: function(jqXHR, ajaxOptions, thrownError){ | |
//alert(xhr.status); | |
alert(jqXHR.response); | |
}, | |
}); | |
$.get('http://0.0.0.0:3000/mongobrokers/broker_hour', function(data){ | |
alert(data); | |
}); | |
}); | |
</script> | |
<script class="include" type="text/javascript" src="../jquery.jqplot.min.js"></script> | |
<script type="text/javascript" src="syntaxhighlighter/scripts/shCore.min.js"></script> | |
<script type="text/javascript" src="syntaxhighlighter/scripts/shBrushJScript.min.js"></script> | |
<script type="text/javascript" src="syntaxhighlighter/scripts/shBrushXml.min.js"></script> | |
<script class="include" language="javascript" type="text/javascript" src="../plugins/jqplot.json2.min.js"></script> | |
</div> | |
<script type="text/javascript" src="example.min.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment