Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts

    ajax form serialize input type file?

    Hi guys... i have a problem... i cant figure out how i can create a ajax function to transfer from the form image ...

    Code:
            $.ajax({
    
                        url: ('profile_picture.php'),
                        data: form.serialize,
                        type: 'POST',
                        dataType: 'html',
                        success: function(data_picture) {
                        var var_data_picture=data_picture;
    
                                $('.login_error_file').html(var_data_picture);    
                        }
    
           });
    the var_data_picture from profile_picture.php will be just a echo text .. something like... file uploaded or whatever but in profile_picture.php i want to move the file and other things. But i dont know how to transfer the file to .php file because obv. with .serialize i cant.

    PHP Code:
      
         move_uploaded_file
    ($_FILES["file"]["tmp_name"],
               
    "uploads/" $_FILES["file"]["name"]); 

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    File upload via Ajax will only work with the new XMLHttpRequest level 2 which is not (yet) supported by jQuery and by every browser

    See: https://developer.mozilla.org/en/XMLHttpRequest also with a table for browser compatibility


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •