开发者

jquery .post not working

开发者 https://www.devze.com 2022-12-17 16:46 出处:网络
High! I just wondered why this won\'t work? $.post($(\"#jsCheckoutForm_1b\").attr(\"action\"), { sLoginName: $(\"#sLoginName\").val(),

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;
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号