There is a form (yii1)

$form = $this->beginWidget('CActiveForm', array( 'action' => Yii::app()->createUrl($this->route), 'method' => 'get', 'id' => 'MyForm' )); ?> <div class="col-md-3"> <div class="row"> <div class="col-md-6"> <?php echo CHtml::submitButton('Find'); ?> </div> </div> </div> </div> <?php $this->endWidget(); ?> И файл js $('#myForm').submit(function(){ alert(1); }); 

When I click send on the form, the alert is triggered.

I need to replace submitButton with ajaxSubmitButton, how can I now determine in js what was done by submit?

  • Do you want to submit the form without restarting ajax? - ultimatum
  • @ultimatum, yes - Fitstd
  • In the yii syntax, I can get a little confused, but according to the classics I can explain, or have you done it already? - ultimatum
  • @ultimatum is still relevant - Fitstd
  • 2
    You're welcome. - ultimatum

1 answer 1

I'll write in classic style, you will transfer to yii:

html:

 <form id="form_id" method="get"> <input type="text" name="input_name"/> <input type="text" name="input_name2"/> <input type="text" name="input_name3"/> <div onclick="sendForm()" >Отправить</div> </form> 

js:

  <script> function sendForm() { var data_form = $('form').serializeArray(); $.ajax({ type: "GET", //метод url: your_URL , //URL на который отправляем запрос data: data_form, //данные из формы success: function() { //код в этом блоке выполняется при успешной отправке сообщения alert("Ваше сообщение отправлено!"); } }); } </script> 

Realization through div . It seems to not miss anything.

PS - you can still cancel the default action for the submit button via preventDefault();