I am making an AJAX request onchange from a rails app. The function is a very simple PUT request:
function quantityChange(id, val) {
$.ajax({
url: 'cart_items/' + id,
method: "PUT",
data: {quantity: val},
success: function() {}
})
}
My issue is the URL that is being called by the request is http://localhost:3004/
and not http://localhost:3004/cart_items/:id
.
I am using jQuery 1.9.1 and have tested the snippet in JSBin. Everything works as expected there but in the Rails app it tries to call the root hostname. If I change the url to cart_items
+ id
without the forward slash the concatenation and url come out almost correct http:localhost:3004/cart_items:id
minus the forward slash that is needed.
I do not understand why the application is defaulting to the root hostname when providing ajax with this url.