Getting a 405 when using $.post with sammy

58 views
Skip to first unread message

devghost

unread,
Mar 19, 2012, 4:47:10 PM3/19/12
to sam...@googlegroups.com
 Hi,

I'm trying to do a post using jquery to a sammy route from a link but I keep getting 405 method not allowed.
If I do a similar post but to a server side url it works.

This is the link I'm using to post with:
  <a href="#/bookmark/delete" onclick="$.post(this.href); return false;">Delete</a>

And this is the sammy route setup:
    Sammy(function () {
        this.use(Sammy.Title);
        this.element_selector = '#content';

        this.get('#/', function (context) {
          ...
        });

        this.post('#/bookmark/delete', function (context) {
            alert('Foo');
        });

    }).run("#/");


Any help is highly appreciated.
Kind Regards,
Robert

devghost

unread,
Mar 20, 2012, 4:54:16 AM3/20/12
to sam...@googlegroups.com
To follow up, if I do an ordinary form post such as shown below. It works as it should.
But somehow I can't get it to work when I want to do a post from a link. My guess, as
I look into it more is that it probably doesn't have anything to do with Sammy, just me
doing something wrong...

This works:
<form action="#/bookmark/delete" method="post">
        <input type="submit" value="Test" />
</form>

And this doesn't, giving a 405:
<a href="#/bookmark/delete" onclick="$.post(this.href); return false;">Delete</a> 


Kind Regards,
Robert

alexandroid

unread,
Mar 21, 2012, 12:25:23 PM3/21/12
to Sammy.js
Well are you sure that "$.post(this.href)" does what you want? I.e.
that this.href points to the right location? Are HTTP post requests
even supposed to with with Javascript hash tags in them?

~Alex

alexandroid

unread,
Mar 21, 2012, 12:26:07 PM3/21/12
to Sammy.js
"supposed to with with" -> "supposed to work with"

devghost

unread,
Mar 22, 2012, 2:48:06 AM3/22/12
to sam...@googlegroups.com

Seems like you're correct, doing some debugging it looks like the
hashtag is stripped off the url. I guess I can put the link between form
tags and issue a submit and that seems to work.

Sure is interesting to know what a submit in a form does extra to
get the hashtag to work though. Will need to do some further digging :)


/:robert
Reply all
Reply to author
Forward
0 new messages