首页 > 解决方案 > 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 保留在站点(会话)上?

感谢您的任何建议。

标签: javascriptajax

解决方案


推荐阅读