1

I have a form that contains file upload inputs, I use iframe to submit those files and the rest data via ajax:

<form id="myform" action="/megogo/web/index.php?r=form/create-order" method="post" enctype="multipart/form-data" target="upload_target">
            ..inputs, file inputs..
</form>
<iframe id="upload_target" name="upload_target" src="#"></iframe> 

I receive data correctly on the server, but I cannot send response status back to the client:

public function actionCreateOrder(){
    //gettting data from $_POST
     $status = 1;
    \Yii::$app->response->format = Response::FORMAT_JSON;
    return $status;
}

Now when form is submitted I receive:

$("#myform").submit( function(e){    

      $.ajax({               
            success: function (response) 
            {    
               console.log(response);
            }
        });

  });

I get html page for response and the message Resource interpreted as Document but transferred with MIME type application/json:. How can I access my status instead? I cannot change enctype because I will not receive uploaded files then. Id appreciate any advice.

5
  • .ajax looks incomplete and you need to echo json response, not return. Commented Jan 28, 2016 at 5:13
  • I post data directly from the form, in jQuery script I just want to get response. If I use $.ajax() to post form.serialize(), I wont receive files. Commented Jan 28, 2016 at 5:19
  • I've used this plugin dropzonejs.com to ajax files. works well if that helps. With this tutorial startutorial.com/articles/view/… Commented Jan 28, 2016 at 5:26
  • unfortunately, I cannot use it. Is there any workaround? Can I change html response, by writing into it on the server? Commented Jan 28, 2016 at 5:59
  • making your controller extending \yii\rest\controller instead of \yii\web\controller won't be an option here ? (check this) Commented Jan 28, 2016 at 11:40

0

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.