JS创建不刷新内容?
Posted
技术标签:
【中文标题】JS创建不刷新内容?【英文标题】:JS create dont refresh content? 【发布时间】:2016-04-24 21:16:29 【问题描述】:在我的站点上,我有一个工作人员列表,其中每个 staff
都可以单击。单击后会打开一个 jquery 移动弹出窗口并使用 AJAX
加载动态内容。在这里,用户可以选择删除选定的员工。但是,成功删除后,我需要关闭弹出窗口并刷新人员列表。我以为.trigger("create")
会这样做,但显然不会。
JQuery 代码:
$("#dynform").on("click", ".delete_staff", function()
var delete_staff = $(this).attr("data");
alert("Click is recorded");
$.ajax(
type: "GET",
url: "include/handler/delete.ajax.php?status=-1&type=" + delete_staff,
dataType: "html",
success: function(response)
alert(response).trigger("create");
);
)
【问题讨论】:
trigger('eventName')
触发/触发指定事件和关联的事件处理程序;您正在使用什么功能来响应该事件?而且,虽然我不确定,但我认为将 trigger()
链接到 alert()
根本不会有任何作用,您的控制台中是否报告了错误?
你说得对Uncaught TypeError: Cannot read property 'trigger' of undefined
其实我想要的是刷新整个页面内容。
在这种情况下,请edit您的问题清楚地解释您想要发生的事情(提供相关的minimal reproducible example代码,以及服务器响应返回的示例数据),以及结果输出应该。您已经展示了您尝试过的内容,但还包括“出了什么问题”(错误消息和不良影响)。
【参考方案1】:
您在第 9 行的代码中有一个严重错误。 请看下面的例子:
$("#dynform").on("click", ".delete_staff", function()
var delete_staff = $(this).attr("data");
alert("Click is recorded");
$.ajax(
type: "GET",
url: "include/handler/delete.ajax.php?status=-1&type=" + delete_staff,
dataType: "html",
success: function(response)
//Let the variable "response" contain the new list, HTML-code generated by the server
//Let the element "dynform" be the list container
//Let the element "myPopup" be the popup you need to close
//Refresh list
$("#dynform").html(response).listview( "refresh" );
//Close popup
$("#myPopup").popup("close");
);
)
【讨论】:
以上是关于JS创建不刷新内容?的主要内容,如果未能解决你的问题,请参考以下文章
使用 RedirectToAction 方法时视图内容不刷新