我试图在表单提交上刷新wordpress中的sidebar.php

时间:2011-03-26 21:45:58

标签: wordpress refresh sidebar

我正在尝试在表单提交上刷新wordpress中的sidebar.php(在sidebar.php的小部件中)。

我在页面上有视频,如果整个页面刷新,则视频必须从头开始播放。

当有人提交表单时,我需要一个简单刷新sidebar.php的解决方案......我不是一个专业的php程序员,这么简单是最好的!

顺便说一句。我正在为表单使用强大的插件。

提前感谢!

1 个答案:

答案 0 :(得分:0)

听起来像ajax的工作!

现在,你可以从头开始做,但那会不必要地痛苦。相反,我建议将jquery添加到您的页面中

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

(使用最新版本,托管在谷歌上)

现在您已经加载了jquery,有许多简单的方法可以在不中断事物流的情况下提交数据。这是我将如何做(我假设你使用method =“post”):

  1. 将您的<input type="submit" >更改为<button>,因此点击它不会触发内置表单提交(这会中断您的视频)。
  2. 将按钮的id属性设置为某个位置,以便您可以像<button id="mysubmitbutton">一样轻松地引用它。 (当你在它的时候,给你所关注的所有表单字段提供id属性,如果你还没有,那么你也可以轻松地引用它们,比如<input type="text" name="firstName" id="firstName">而不仅仅是<input type="text" name="firstName">
  3. 在您网站的<head>部分内,添加一些类似于以下内容的代码:

  4. <script type="text/javascript">
    
    //makes it so that it goes after the html document is ready for it
    
    $(document).ready(function() {
    
       //this ties a onclick event to your button you made
    
       $("#mysubmitbutton").click(function(){
    
        //when the button is clicked, it will asychronously post to where you want it to
    
          $.post("urlthatwasinyouractionequalsattribute.php", 
    
          { 
    
             //put all your post variables here, referencing the ids you made earlier
    
             firstName: $("#firstName").val(), 
    
             time: $("#time").val() //be sure you don't have a trailing comma on the last one
    
          },
    
          function(data) {
    
            //data is whatever the other website sends back. do whatever you want here...
    
            alert("Result: " + data);
    
          });
    
       });
    
    });
    
    </script>
    

    点火它应该有效。显然,您需要更改值以使其与您的表单匹配等。

    希望有所帮助!如果有,请标记为答案。

相关问题