I'm trying to send a GET
request to my /routes/
controller so I can receive some data back, right now I have
function fetchMarker(id) {
var data;
$.ajax({
type: "GET",
url: '/routes/',
data: id,
dataType: "JSON",
success: function(data) {
console.log(data)
}
});
}
But the problem is is when I do that, Firebug tells me:
"NetworkError: 404 Not Found - http://10.0.0.24:3000/routes/?15"
I believe this is being caused by the ?, I've recently switched to Ruby on Rails so I don't know if this is normal but rake routes tells me it has to be /routes/(params[:id]) so I'm assuming just the ID number.
My controller:
def show
@route = Route.find(params[:id])
respond_to do |format|
format.html
format.json { render json: @route }
end
end
Thanks in anticipation!
You remove the data, by removing the data:{}, $. ajax({ url: 'ListCustomer', error: function(xhr, statusText, err) { alert("error"+xhr. status); }, success: function(data) { alert(data); }, type: 'GET' });
You can either specify the URL or not when sending the AJAX request.
Just append the id
to the url
, instead of sending it as data
:
function fetchMarker(id) {
var data;
$.ajax({
type: "GET",
url: '/routes/' + id,
dataType: "JSON",
success: function(data) {
console.log(data)
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With