Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


How to send complete form through AJAX ?

When i receive file in php I am only getting post there not image

<form action="" method="post" enctype="multipart/form-data" id="posting">
      <img src="<?php echo $user_data['profile']; ?>" alt = "<?php echo $user_data['firstName']; ?>" class='post_pro'/>
      <textarea name="post" placeholder="Hey <?php echo $user_data['firstName'] ?>,want to share something with us..."></textarea>
      <input type="file" name="post_pic" id="post_pic" style="color:transparent">
      <input type="submit" value="SHARE">

            url  : "request/post.php",
            type : "POST",
            data : new FormData(this),
            dataType : "text",
            beforeSend : function(http){
            success : function(response,status,http){ 

            error : function(http,status,error){
                $("#show").html("<span class=\"error\" data-icon ='&#xea0f;'>Something went wrong with server.Try Again</span>");


1 Answer

Shane Oliver
Shane Oliver
19,977 Points

You need to serialize your form data

    data: $("posting").serialize(),
    // rest of code