数据库中的记录被删除,但前端界面上仍保留删除按钮
P粉118698740
P粉118698740 2023-08-29 17:04:46
[HTML讨论组]
<p>当点击删除按钮时,它成功地从数据库中删除记录。但是在前端页面上并没有立即删除,需要重新加载或刷新页面后才会显示删除结果。</p> <p>我的视图:</p> <pre class="brush:php;toolbar:false;">@foreach (var item in Model) { &lt;a href=&quot;#&quot; class=&quot;phone_number&quot; onclick=&quot;del(this)&quot; data-id=&quot;@item.id&quot;&gt; &lt;i class=&quot;fas fa-trash-alt&quot;&gt;&lt;/i&gt; &lt;/a&gt; } &lt;script&gt; function del(x) { var url = '@Url.Action(&quot;deleteRent&quot;, &quot;Home&quot;)'; var rd = x.dataset.id debugger $.ajax({ url: url, type: 'POST', data: { id: rd }, success: function (data) { if (data.length == 0) // No errors alert(&quot;删除成功!&quot;); }, error: function (jqXHR) { // Http Status is not 200 }, complete: function (jqXHR, status) { // Whether success or error it enters here } }); }; &lt;/script&gt;</pre></p>
P粉118698740
P粉118698740

全部回复(2)
P粉466909449

请在alert后面添加window.location.reload()代码....

success: function (data) {
                if (data.length == 0) // 没有错误
                    alert("删除成功!");
                    **window.location.reload();**
            },

此代码在成功后会自动重新加载您的页面

P粉014218124

实际上,你从数据库中删除了数据,但你没有刷新页面。

要么,你使用Dipendrasinh Vaghela的答案并刷新整个页面。

或者,如果你有一个在DOM中搜索和显示的函数,你可以在删除成功时调用它。这将“只”更新显示数据的部分。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号