1

How I can upload images and all element with one AJAX? I would to upload images and send filename to database.... All element working fine, but I get nothing value in the images row.

here my AJAX CODE :

  $(document).ready(function() {
     $("#FormSubmit").click(function (e) {

        e.preventDefault();

        if($("#contentText").val()==="")
        {
            alert("Please enter some text!");
            return false;
        }

        var myData = $("#postA").serialize(); 

        jQuery.ajax({
            type: "POST", 
            url: "response.php", 
            data:myData,
            success:function(response){
            $(response).hide().prependTo("#responds").fadeIn("slow");
            document.getElementById("postA").reset(); 
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert(thrownError);
            }
        });
    });

and here my form code :

  <form id="postA">
    <textarea name="content_txt" id="contentText" ></textarea>
    <input type="text" name="id_userto" />
    <input type="text" name="thpost" />
    <input type="file" name="thpostimg" />
    <input type="text" name="thpostvid" />
    <input type="text" name="thpostmsc" />
    <input type="text" name="thpostlic" />
    <input type="hidden" name="content4txt" value="TRUE" />
    <button id="FormSubmit">Share</button>
  </form>
rami-yrm
  • 57
  • 1
  • 11

1 Answers1

2

Short Answer: You can't.

You can't post files with ajax How can I upload files asynchronously?

But it can be faked. The accepted answer to this question may help jQuery Ajax Submit form elements with multipart/form-data (Image/Video)

Community
  • 1
  • 1
andrew
  • 9,313
  • 7
  • 30
  • 61