I'm trying to build an ajax request that will eventually allow users to sort a list by clicking buttons next to each item. Here's what I have so far:
upLinks.on('click', function(e) {
var link;
e.preventDefault();
link = $(this)[0];
console.log(link.pathname);
$.ajax({
type: 'PUT',
url: link.pathname
});
return false;
});
console.log(link.pathname)
logs out /projects/11/project_items/104/sort
to the console, as expected. However, the ajax request returns an error:
PUT http://localhost:3000/projects/11 400 (Bad Request)
Looking at the server logs, it is in fact going to /projects/11
, not /projects/11/project_items/104/sort
for some reason. According to the jQuery docs, /projects/11
would be the default parameter for ajax in this case, because that's the route of the current page. Which leads me to believe it's ignoring the url parameter altogether.
If I change HTTP method type to GET
, the ajax runs as expected. Is there some reason /projects/11/project_items/104/sort
is not an acceptable url for a PUT
request? I thought that because I'm updating data (with the new position) a PUT
request would be the most logical option.