简体   繁体   English

打开没有更改页面的更改DIV

[英]Open change DIV without refresh page

I extract this example code of a website to test it, the code have to show a text that if you click on it show you the code of test.php without refresh the page. 我提取了该网站的示例代码进行测试,该代码必须显示一个文本,如果单击该文本,则无需刷新页面即可显示test.php的代码。

localhost/testing/index.php 本地主机/测试/ index.php

<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
   $('#div-btn1').click(function(){
      $.ajax({
        type: "POST",
        url: "test.php",
        success: function(a) {
                $('#div-results').html(a);
        }
       });
   });
});
    </script>
</head>
<body>
<a id="div-btn1" style="cursor:pointer;">Open file</a>

<div id="div-results"></div>
</body>
</html>

localhost/testing/test.php 本地主机/测试/ test.php

<?php echo "<p>Hello world</p>";?>

As you can see it´sa very simple code but I can´t do it works, I can see the content of index.php but when I click in "Open file" nothing occurs. 如您所见,这是一个非常简单的代码,但我无法完成它,我可以看到index.php的内容,但是当我单击“打开文件”时,什么也没有发生。

I'm working in a XAMPP server. 我正在XAMPP服务器上工作。

I've check your code on my local (ubuntu LAMP), just switched to current version of jquery like so: 我已经在本地(ubuntu LAMP)上检查了您的代码,就像这样切换到了当前版本的jquery:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

and it works :) 它有效:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM