删除照片后刷新页面 [英] Refresh page after delete photo

查看:130
本文介绍了删除照片后刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有javascript功能,可以从数据库和服务器中删除照片.一切正常,我删除了照片,但该照片仍在我的浏览器中.我有问题.如何只在javascript端刷新?

Hi I have function in javascript where I delete photos from database and from server. It work fine, I delete photo but this photo is still in my browser. I have question. How can I refresh only on javascript side?

 container.addEventListener("click", function(e){
                if(e.target.tagName == 'BUTTON'){
                     var id = e.target.dataset.type;
                   var r = confirm("Are You sure to delete?");
if (r == true) {
    $.ajax({
        type: 'POST',
        url: 'index.php?r=gallery/deletep&name='+id,
        dataType: 'html'
    });
} 
                }
    });

现在我想添加

location.reload();

location.reload();

ajax之后,但我不想刷新所有页面.如何从浏览器动态删除?

after ajax but I don't want to refresh all page. How Can i delete dynamically from browser?

推荐答案

您无需重新加载整个页面即可删除图像.在AJAX调用的成功回调中,使用jQuery中的 remove() API.

you don't need to reload the whole page to remove the image. Use remove() API from jQuery in the success callback in AJAX call.

   $.ajax({
    type: 'POST',
    url: 'index.php?r=gallery/deletep&name='+id,
    dataType: 'html',
    success: function(response){
       $('img#id').remove();
    }
});

这篇关于删除照片后刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆