I'm using $.post()
to do the following...
$.post('login',details);
I would assume this POST's the data to login
but all I can see happening is the details being attached to the url as if it's doing a GET request to the page I'm on rather than a POST to my login
page. Why would this be happening? My login
page is meant to redirect the user to a new page once their login request has completed so ideally I'd like the POST to go to the login
page so that the user can be redirected.
The details
contents are { username: "username", pasword: "password"}
and the login
page is a login.java
page which is using Jersey.
POST to GET is often caused by you using a wrong URL.
I think your serverside program is expecting that the URL ends in / and redirects to that address using HTTP 301 or 302 response; according to specs this means that GET must be issued instead of POST.
Try using "login/" instead; also consider that your code should be callable from any url on your site; preferably anchor the urls to server root, thus "/login/"!
If $.post don't works, try the $.ajax function instead:
$('#target').click(function() {
var formdata = $('#loginFrm').serialize(); // will produce { username: "username", pasword: "password"}
$.ajax({type: "POST",
url: "urlto/tojavapage",
data: formdata ,
success: function(data) {
// div container to display error msg
$('#loginmessage').html(data);
}
});
return false;
});`
make sure your submit button has a click event that call this e.g
<input type="button" value="login" id="target" /> <div id="loginmessage"> </div>
thanks
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