2

I have post form with submit button before submit i need to call c# code behind get hash and then change value of hidden input.

Code behind is calling but problem is that while i get result from c# code form is submiting how i can first get result and then submit form?

Jquery:

$('#pay_form').submit(function(){
       GetHash();
    });


 function GetHash()
    {
        var amount = $('#txtInAmount').val();
        $.ajax({
            url: '/Transactions/GetOrderCodeHah',
            type: 'POST',
            dataType: 'json',
            data: { Amount: amount },
            success: function (result){
                $('#txtOrderCode').val('231321321321321321');
                $('#txtCheck').val(result.hash);
            },
            error: function(){
                return false;
            }
        });
    }
2
  • Why on earth are you doing that? Why not do it all after submitting? Commented May 24, 2012 at 20:18
  • And how i can do that? can you provide some examples? Commented May 24, 2012 at 20:21

1 Answer 1

2

You need to return false; from the submit() handler, then explicitly submit() the form in the AJAX callback.

Sign up to request clarification or add additional context in comments.

2 Comments

and how i can submit in ajax callback?
$('#pay_form')[0].submit(). The [0] gets the native DOM element, to avoid firing your submit handler again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.