How to refresh modal body when submit Ajax Post?

亡梦爱人 提交于 2021-02-11 09:39:07

问题


Im submitting ajax request using Bootstrap Modal when i submit i want refresh modal body. it means what i have saved from my form im showing my modal body i want show that row in table. when i use this that table got hide not refreshing anything rong ?

 $('#uploadform').submit(function(e) {

        e.preventDefault();

        var formData = new FormData();
        formData.append('file', $('input[type=file]')[0].files[0]);
        formData.append('task_id','{{$task->id}}');
        formData.append('title',$('#title').val());

        $.ajax({
            type:'POST',
            url:'{{url('/uploadTask')}}',
            data:formData,
            success:function(data){

                $("#images-table").replaceWith($('#images-table', $(data)));

                $("#some_form")[0].reset();

            },
            error:function (data) {
                alert('error');
            },
            async:false,
            processData: false,
            contentType: false,
        });
    });

回答1:


You can simply refresh the Modal html by putting some new html into it like:

success:function(data){
    // here data contains the response for your ajax call
    var newHTML = data;
    $("#images-table").html(newHTML);  // This will put new html and remove old
}


来源:https://stackoverflow.com/questions/42051048/how-to-refresh-modal-body-when-submit-ajax-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!