【发布时间】:2016-11-15 18:17:41
【问题描述】:
我有一个带有 div (id=reqs) 的 html 页面。我想在页面加载后加载 div 的 html 内容。所以我创建了一个 ajax 调用,它使用 php 从数据库中获取数据并将其“回显”到 html 代码中以填充到 div 中。
我的html:
<html>
<body>
<div class="content" id="reqs"></div>
<script> $(document).ready(function() {
$.ajax({
type: "GET",
url: '../getreqs',
success: function(data) {
$('#reqs').html($data);
}
}); }); </script>
</body>
</html>
我的 php ajax 函数:
$data .= "<div class=\"toggle store-history-toggle\">";
$data .= "<a href='#' class=\"toggle-title\"><strong class=\"bg-yellow-dark\">" . "YP" . "</strong>" . "ER" . "<i class=\"fa fa-plus\"></i></a>";
$data .= "<div class=\"toggle-content\">";
$data .= "<div class=\"cart-costs\">";
$data .= "<h4>Details</h4>";
$data .= "<h5><strong>Name</strong><em>John Doe</em></h5>";
$data .= "</div>";
$data .= "</div>";
echo $data;
我的问题是我的 href="#" (应该扩展显示其下方详细信息的 div)不起作用,但如果我复制从我的 php 生成的完全相同的 html 并将其粘贴到我的 html 中它可以工作完美。
更多信息: - 我的 html 代码在文件夹“htmlroot/子文件夹”中 - 我的 php 代码在文件夹“htmlroot”中
我的解决方法:
- 我在herf="#" 和href='#' 之间切换
- 我有 php 代码给我href="LINKREF",并在获取数据后用我的 ajax 函数将 LINKREF 替换为 #
var res = String(data).replace(/LINKREF/g, "#");
这些尝试都不起作用
【问题讨论】:
-
你能显示不使用php ajax的工作的sn-p吗?
-
不应该
$('#reqs').html($data);是$('#reqs').html(data);而是在.success()下?
标签: javascript php html ajax