问题描述
下面是我的 javascript 文件中的代码,它在写入一些文本后对我的 mysql 进行排序,以便仅返回与该搜索匹配的结果。
但是,我正在尝试使用 <nav>
和 <a href= "document.php">
使我的搜索结果成为我的搜索结果,以便在上述过滤器之后转到有关我的搜索结果的页面。然而,当我尝试在我的 javascript for 循环中编写这个 html 和 php 代码时,我的问题就出现了。
我搜索过类似的问题,但使用 document.write()
似乎很乏味,因为我想要的 html 代码中的许多引号似乎有错误。
function search(age) {
console.log(age);
fetchSearchData(age);
}
function fetchSearchData(age) {
fetch('search.php',{
method: 'POST',body: new URLSearchParams('age=' + age)
})
.then(res => res.json())
.then (res => viewSearchResult(res))
.catch (e => console.error ('Error: ' + e))
// This is the problematic code
function viewSearchResult(data) {
const dataViewer = document.getElementById('dataViewer');
dataViewer.innerHTML = "";
for(let i=0; i<data.length; i++) {
const li = document.createElement("li");
li.innerHTML=data[i]["name"];
dataViewer.appendChild(li);
<ul id=\"dataViewer\">
<?php foreach($data as $i) { ?>
<nav>
<li>
<a href=\"search.php\">
<?php echo $i[\"name\"];?>
</a>
</li>
</nav>
<?php } ?>
</ul>
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)