PJax ActiveForm and GridView problem

Hi,

I try create a ActiveForm with a GridView for a many to many relation like this:




<?php $form = ActiveForm::begin(); ?>

 	<?= $form->field($model, 'name')->textInput(['maxlength' => 100]) ?>


	<?php \yii\widgets\Pjax::begin(); ?>

	<?= \yii\grid\GridView::widget([

    	'id' => 'phonesGrid',

    	'dataProvider' =>  new ArrayDataProvider([

        	'allModels' => $fones,

        	'sort' => [

            	'attributes' => ['number', 'ramal'],

        	],

        	'pagination' => false,

    	]),

    	'columns' => [

        	[

         		'number',

         		'ramal',

				[

					'class' => \yii\grid\ActionColumn::className(),

					'template' => '{update}{delete}',

					'header' => Html::a(

						'<i class="glyphicon glyphicon-plus"></i>&nbsp;New',

						null, ['href' => 'javascript:NewPhone();']

					),

					'buttons' => [

						'update' => function ($url, $model) {

							return Html::a('<span class="glyphicon glyphicon-pencil"></span>', null, [

					    		'title' => Yii::t('app', 'Update'),

					    		'href' => 'javascript:UpdatePhone(' . $model['seq'] . ');'

							]);

						}

					]

				]

        	]

    	]);?>

    	<?php \yii\widgets\Pjax::end(); ?>

<?php ActiveForm::end(); ?>



My Javascript functions:




	function NewPhone()

	{

		$('#ProsFoneForm').attr('action', '/prospecttelefone/create');

		$('#phoneModal').modal('show');


		$( "#salvarButton" ).click(function() {

			$('#prospecttelefone-prospect_id').val($('#prospect-id').val());

			var data=$('#ProsPhoneForm').serialize();

			$.ajax({

	    		type: 'POST',

	    		url: '/prospect/new-fone',

	    		data: data,

	    		success:function(data) {

	        		$('#phoneModal').modal('hide');

	        		$.pjax.reload({container: '#PhonesGrid'});

	        		return false;

	    		},

	    		error: function(data) { // if error occured

	        		alert('Error, try again.');

	    		},

	    		dataType:'html'

			});

		});

	}


	function AlteraTelefone(seq, id)

	{

		var data = "seq="+seq;

		$( "#salvarButton" ).click(function() {

			var data=$('#ProsPhoneForm').serialize();

			$.ajax({

	    		type: 'POST',

	    		url: '/prospect/altera-fone?seq=' + seq,

	    		data: data,

	    		success:function(data) {

	        		$('#phoneModal').modal('hide');

	        		$.pjax.reload({container: '#PhonesGrid'});

	        		return false;

	    		},

	    		error: function(data) { // if error occured

	        		alert('Error, try again.');

	    		},

	    		dataType:'html'

			});

			return false;

		});

	}



My problems are:

  1. When $.pjax.reload({container: ‘#PhonesGrid’}); is call the create or update action is call twice one with pJax and another normal GET;

  2. When the create or update actions is call by pJax the form data is not send and the data of form is lost. In Yii 1 when I call $.fn.yiiGridView.update in Javascript

the form data is sent with the GET request.

Can anyone help me with this?

Thanks.