2

How can I add a JavaScript function before and after the AJAX call?

This my Yii Code:

echo CHtml::ajaxSubmitButton('Create Invoice',$this->createUrl('url'),
array(
   'type'=>'POST',
   'data'=> 'js:{"merchant_id": $("#merchantSearchForm_merchant_list").val() }',
   'success'=>'js:function(string){ $("#merchantProfileForm").html(string); }'
),array('class'=>'someCssClass',));

I need to call a JavaScript function when the user clicks on button, and when the request returns the response, I need to call another JavaScript function.

The workflow would be:

  1. User clicks on button
  2. Call loader(); function
  3. AJAX request and return the response
  4. Call hidLoder(); function

1 Answer 1

2

Already you are calling some js function after ajax response (in success)

For before ajax call option: you can set another option in ajaxSubmitButton

 'beforeSend'=>'js:function(data){
        }',             
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.