【问题标题】:on button click change content from an external div在按钮上单击更改来自外部 div 的内容
【发布时间】:2012-09-05 09:03:12
【问题描述】:

我在 wordpress 的后端有这个按钮,如果单击它,它应该从我的主题的一个文件中更改一个 div 的内容。我的代码可能离我应该去的地方很远......

<input type="submit" value="load()" id="start_chat" /> //the button
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">

 $.ajaxSetup ({  
            cache: false  
        });  

    var loadUrl = "facut_mine3.php";  // the file where there is only a new content for the div #eu_la
    $("#start_chat").click(function(){  
        $("#eu_la").load('http://www.fattorefamiglia.com/wp-content/themes/child_care_creative/layout_home_page2.php').html(loadUrl);  //this is the file that I want to change, with the div #eu_la
    });  
</script>

当然,当我单击按钮时没有任何变化。有没有其他方法可以做到这一点?

【问题讨论】:

  • 将错误处理代码放入您的 ajax 调用中以找出您遇到的错误。
  • 您的意思是我不能从不同的文件更改文件的内容?没有解决办法?
  • @Ashish 我不知道该怎么做,我在谷歌上找不到怎么做。有链接吗?
  • 而不是 $().load() 使用 $.ajax() 你可以在api.jquery.com/jQuery.ajax找到更多关于 $.ajax 的信息
  • 让它变得简单。您在页面上有一些内容。当你点击一个按钮时,你需要在那个地方显示一些其他的内容。这是你的终极目标吗??

标签: php html ajax wordpress


【解决方案1】:

为了允许跨域的 Ajax 请求,在 ROOT 中设置一个 .htaccess 文件,包含以下内容:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

另见:

  • enable-cors.org
  • code.google.com/p/html5security/wiki/CrossOriginRequestSecurity

【讨论】:

  • 我这样做了,但什么也没发生。顺便说一句,那个文件中有一些代码,我只是把你的代码和另一个放在一起......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多