开发者

JQuery conditional submit after ajax call

1) The form submit action is changed by the document ready fn to make an ajax call

2) If the data from the ajax is not 'No probs' then it puts the error message in a div and changes the value of the submit, so that a second click takes you to the standard action. This bit works.

3) If there is not an error I want it to post the standard action: See alert('Fred1'); (here I have tried $('#addcreditdetails').submit() also

I have tried lots of things but cannot get 3) to work.

    <script>

    var chrisReady = function () {

     var submitFunction = function (event) {
      //console.log(submitval);

      var chrisPoster = function (data) {
       alert(data);
       if (data=='No probs') {
        $('#dealwarning').html('CC');
        alert('Fred1');
        $('#addcreditdetails').unbind('submit');
        $('#addcreditdetails').submit();
        alert('Fred2');
       }
       else {
        $('#dealwarning').html(data);
        $('#submit').val('Confirm Add Credit');
        jQuery('#addcreditdetails').开发者_JAVA百科unbind('submit');
       }
      };

      var amountval = $('#amount').val();
      var currval = $('#curr').val();
      var accountnoval = $('#accountno').val();
      var submitval = $('#submit').val();


      var postData = { 
       amount: amountval,
       curr: currval,
       accountno: accountnoval,
       submit: submitval
      };

      $.post('docheckcredit.php', postData, chrisPoster);
     }

     $('#addcreditdetails').bind('submit', function (event) {
      event.preventDefault();
      submitFunction(event);
     });
    }

$(document).ready(chrisReady);
</script>";


Could you try replace the

 $('#addcreditdetails').submit();

to

 $('#addcreditdetails').first().submit();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜