javascript - JS/POST/AJAX 成功 - 失去页面上的其他 js 功能
问题描述
我有这样的脚本可以正常工作,但成功后我无法对 js 执行任何操作,直到刷新页面。
我的代码如下所示:
<script>
$("#submit_comment").click(function() {
var url = "{$sitepath}/comment.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#cform0").serialize(), // serializes the form's elements.
success: function(data)
{
$("#myHeader").load(location.href + " #myHeader > *", "");
}
});
return false; // avoid to execute the actual submit of the form.
});
</script>
如果我改变它的工作原理
$("#myHeader").load(location.href + " #myHeader > *", "");
至:
$("#myHeader").load("#myHeader");
但随后myHeader
再次出现myHeader
在页面上。问题。是否有可能加载 myHeader 并将 JS 保留在站点(会话)上?
感谢您的任何建议。
解决方案
推荐阅读
- docker - docker-compose 中的 Traefik 加载旧的 docker 镜像
- python - 使用 Get 的奇怪行为错误 - 提供的字符串键索引无效
- google-sheets - Google表格:如果满足条件,则加入数据
- authentication - 在 github 中尝试使用 PAT 进行身份验证时出现错误 403
- d3.js - d3.js - 了解将元素附加到 g 的箭头函数
- android - 从嵌套的 nav_graph 导航到主 nav_graph 中的特定片段以全屏打开它
- node.js - 护照-totp 认证的认证问题
- reactjs - React 在使用扩展运算符更改状态时呈现,但在传递数组本身时不呈现
- foreign-keys - 如何在实体内部的android房间中使用外键和复合键,它只保存一个键,另一个是隐式给出的
- c# - 为什么在 C# 中使用具有继承接口的具体类实例的泛型接口的变量会失败?