简体   繁体   English

如何使用AJAX发布完整表格?

[英]How can I post full form with AJAX?

How I can upload images and all element with one AJAX? 如何使用一个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 : 这是我的AJAX代码:

  $(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>

Short Answer: You can't. 简短的回答:不能。

You can't post files with ajax How can I upload files asynchronously? 您不能使用ajax发布文件如何异步上传文件?

But it can be faked. 但是它可以被伪造。 The accepted answer to this question may help jQuery Ajax Submit form elements with multipart/form-data (Image/Video) 对此问题的可接受答案可以帮助jQuery Ajax提交具有multipart / form-data(图像/视频)的表单元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM