jquery .post not working
High!
I just wondered why this won't work?
$.post($("#jsCheckoutForm_1b").attr("action"), {
sLoginName: $("#sLoginName").val(),
sPassword: $("#sPassword").val()
}, function(sData){
alert(sData);
}
);
the fun thing is that if i hard code the acti开发者_Go百科on in stead of using $("#jsCheckoutForm_1b").attr("action")
, the form is submitting. Alerting $("#jsCheckoutForm_1b").attr("action")
does work fine (meaning it displays the right url to use).
Any ideas?
You may need to have return false;
on the onclick function of the submit button.
Your code looks fine. I would cache some variables and test them.
var form=$('#jsCheckoutForm_1b'),
url=form.attr('action'),
login=$('#sLoginName'),
password=$('#sPassword');
console.log(form, url);
form.submit(function(){
$.post(url,
{sLoginName: login.val(), sPassword: password.val()},
function(sData){
});
return false;
});
精彩评论