title: Upload Ajax file in yii2
body: <p>I want to upload file using Ajax in yii2 framework
  this is my code, but in controller "get Instance" return null because of serialize data; how can i do this?</p>
  
  <p>This is my controller:</p>
  
  <pre><code>&lt;?php
  public function actionUpdate($id)
      {
              $model = Signature::findOne([
                  'user_id' =&gt; $id,
              ]);
              if ($model-&gt;load(Yii::$app-&gt;request-&gt;post())) {
                  $model-&gt;file = UploadedFile::getInstance($model, 'file');
                  $model-&gt;file-&gt;saveAs('uploads/signature/' . $model-&gt;user_id . '.' . $model-&gt;file-&gt;extension);
                  $model-&gt;url = 'uploads/signature/' . $model-&gt;user_id . '.' . $model-&gt;file-&gt;extension;
  
                  if ($model-&gt;save()) {
                      echo 1;
                  } else {
                      echo 0;
                      echo $model-&gt;file;
                  }
              } else {
                  return $this-&gt;renderAjax('update', [
                      'model' =&gt; $model,
                  ]);
              }
      }
  ?&gt;
  </code></pre>
  
  <p>This is my script code
  I can't get my file in controller and it return null</p>
  
  <pre><code>&lt;?php $script = &lt;&lt;&lt;JS
  
  $('form#{$model-&gt;formName()}').on('beforeSubmit', function(e)
  {
      var \$form = $(this);
  
      $.post(
      \$form.attr("action"),
      \$form.serialize(),
  
      )
          .done(function(result){
          if(result == 1)
          {
              $(document).find('#update_signature_modal').modal('hide');
              $.pjax.reload({container:'#branchesGrid'});
              //alert();
          } else {
              alert(result);
          }
          }).fail(function()
          {
              console.log("server error");
          });
          return false;
  });
  
  JS;
  $this-&gt;registerJs($script);
  ?&gt;
  </code></pre>