duanbi2760
duanbi2760
2017-01-19 08:50

如何在ajax中使用formdata发送String数据

<script type="text/javascript">
$(document).ready(function(){
    $("#btnUpdate").click(function(){
        alert($("#frm_data").serialize());
        var formData = new FormData($("#frm_data")[0]);
        var Desc= CKEDITOR.instances.editor1.getData();

        $("#btnUpdate").attr('value', 'Please Wait...');
        $.ajax({
            url: 'update_job.php',
            data: formData,
            cache: false,
            contentType:false,
            processData:false,
            type: 'post',
            success: function(response)
            {
                $("#btnUpdate").attr('value', 'Update');
            }
        });
        return false;
    });
})
</script>

i use ckeditor for textarea field. but its can update value with new value, so i want to use another way with send textarea value with form data.
so how to send Desc data with fromData. in ajax.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongshuohuan5291 dongshuohuan5291 4年前

    To achieve this you can use the append() method of FormData to add whatever additional information you require:

    $("#btnUpdate").click(function(e) {
        e.preventDefault();
        var $btn = $(this).attr('value', 'Please Wait...');
        var formData = new FormData($("#frm_data")[0]);
        formData.append('desc', CKEDITOR.instances.editor1.getData());
    
        $.ajax({
            url: 'update_job.php',    
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            type: 'post',
            success: function(response) {    
                $btn.attr('value', 'Update');
            }
        });
    });
    
    点赞 评论 复制链接分享

相关推荐