我有一个 PHP 文件 Test.php,它有两个函数:
<?php
echo displayInfo();
echo displayDetails();
?>
JavaScript:
<html>
...
<script type="text/javascript">
$.ajax({
type:'POST',
url: 'display.php',
data:'id='+id ,
success: function(data){
$("#response").html(data);
}
});
</script>
...
<div id="response">
</div>
</html>
它返回来自 jQuery 的响应。响应显示为 <a href=Another.php?>Link</a>
。当我单击 test.php
中的 Another.php 链接时,它会加载到另一个窗口中。但我需要它来加载相同的 <div> </div>
区域而不改变 test.php
的内容,因为它有 displayInfo(), displayDetails()
。或者是否可以在<div> </div>
内加载PHP页面元素?
如何解决这个问题?
最佳答案
如果我理解正确的话,您希望使用 a
链接取消导航,但触发 AJAX 功能?
在这种情况下:
$("#mylink").click(function() {
$.ajax({ type: "POST", url: "another.php", data: {id: "somedata"}, function(data) {
$("#response").html(data);
});
return false;
});
关于php - 如何在 jQuery 的同一窗口中加载 PHP 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/370850/