【问题标题】:Webpage should not refresh网页不应该刷新
【发布时间】:2014-12-11 11:55:46
【问题描述】:

我需要一个网页在点击时不应该刷新,但它应该传递该链接的 id。

<?php echo "<a href='http://localhost/ss/index.php?albumid={$id}#photo'><img src=http://localhost/ss/admin/html/".$p['path']." class='img-responsive' alt='' data-toggle='modal' data-target='.bs-example-modal-lg1'></a>";

<?php if(isset($_GET['albumid'])) $mid = $_GET['albumid']; ?>

我尝试过 ajax,但它不起作用。 可能吗?你能帮帮我吗?

【问题讨论】:

  • 我尝试使用 ajax jquery。但问题是未定义的索引:albuid

标签: javascript php jquery html refresh


【解决方案1】:

可以传递id,然后进行ajax调用,这样可以避免页面刷新。

以下是代码,如何传递 id 并使用 jQuery 进行 ajax 调用

&lt;div id='link1'&gt;&lt;a href='yourfilename.php?id=1'&gt;abc&lt;/a&gt;&lt;/div&gt;

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#link1").click(function(){
        $.ajax({url:"abc.php",success:function(result){
      //Code after the success of ajax call
    }});
  });
});
</script>

它一定会帮助你亲爱的

【讨论】: