簡體   English   中英

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

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

如何使用一個AJAX上傳圖像和所有元素? 我將上傳圖像並將文件名發送到數據庫。...所有元素都工作正常,但是圖像行中沒有任何值。

這是我的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);
            }
        });
    });

這是我的表單代碼:

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

簡短的回答:不能。

您不能使用ajax發布文件如何異步上傳文件?

但是它可以被偽造。 對此問題的可接受答案可以幫助jQuery Ajax提交具有multipart / form-data(圖像/視頻)的表單元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM