Irakli Lekishvili
Irakli Lekishvili

Reputation: 34158

asp.net mvc3 razor and jquery submit

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

Upvotes: 2

Views: 1231

Answers (1)

SLaks
SLaks

Reputation: 887453

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

Upvotes: 2

Related Questions