javascript - Sending files and other data from JS to PHP -


i have form need send file , other data in php.

            <?php echo form_open("admin/add_agent_request", array("id" => "new_agent_form", "enctype" => "multipart/form-data")) ?>                 <div class="box-body">                     <div class="form-group">                         <label for="email">email</label>                         <input name="email" id="email" type="text" class="form-control" placeholder="enter email">                                          </div>                     <div class="form-group" id="a">                         <label for="photo">add photo</label>                         <input name="photo" type="file" id="photo" class="a">                         <p class="help-block">max photo size - 2 mb</p>                     </div>                 </div>                 <!-- /.box-body -->                 <div class="box-footer">                     <button name="new_agent_button" type="submit" class="btn btn-primary">submit</button>                 </div>             </form> 

ajax script

<script>     $('#new_agent_form').submit(function(e)     {         e.preventdefault();         var me = $(this);         var form_data = {             email: $('#email').val(),             photo: document.getelementbyid('photo').files[0]         };         $.ajax(         {             url: me.attr('action'),             type: 'post',             data: form_data,             datatype: 'json',             success: function(response)             {                 if(response.success == true)                 {                     $('#message').append(                         '<div class="alert alert-success">'+                         response.messages.error+                         '</div>');                 }             }         });     }); </script> 

controller need data.

public function add_agent_request() {     $data['success'] = true;     $data['messages']['error'] = 'test';     echo json_encode($data); } 

if object not send file, passed perfectly, if object contains file nothing sends. how can send object file?


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -