저는 PHP로 시작 했으므로 PHP로 jQuery 아약스를 옮기려고합니다. 여기 PHP를 자바 스크립트로 옮기기
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT * FROM agency ORDER BY name";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)){
$id = $row['id'];
$name = $row['name'];
echo "<li class=\"agency\"><a href=\"contentAgency.php?id=$id\">$name</a><ul class=\"agency-sub\"></ul></li>";
}
include 'closedb.php';
?>
내 현재 JS 기능입니다 : 여기 내 PHP 파일 인 showContentAgency 여기
//Add Agency content
$("ul.top-level").on("click", "li.agency a", function (event) {
if($(this).next().length) {
var numbs = $(this).attr("href").match(/id=([0-9]+)/)[1];
showContentAgency(numbs, this);
} else {
$(this).closest('ul').find('a').removeClass('sub-active');
}
event.preventDefault();
});
그리고있다(); 함수 :
function showContentAgency(id, elem) {
$.post("assets/includes/contentAgency.php?id=id", {
id: id
}, function (data) {
$(elem).addClass("nav-active").parent().find("ul").html(data).show();
});
}
내가 원하는 것은 PHP에서 jQuery를 삽입하는 대신 순서가 지정되지 않은 목록을 렌더링하도록하는 것입니다. 이것은 현재 위의 PHP 파일에 등장하는 방법입니다 :
echo "<li class=\"agency\"><a href=\"contentAgency.php?id=$id\">$name</a><ul class=\"agency-sub\"></ul></li>"
그래서 나는 <ul class="agency-sub">
목록을 채울 수있는 PHP를하고 싶습니다.
당신이 묻는 것은 약간 명확하지 않습니다. PHP 스크립트가 전송하기 전에 PHP 스크립트가 UL을 채우게하려면 그냥 그렇게해야합니다. 무슨 문제 있니? 나중에 PHP를 동적으로 채우려는 PHP를 원하십니까? – Chuck
정확하게, 나는 PHP가 목록을 채우길 원합니다. 하지만 나는 PHP에 대해 너무 익숙해 목록 안의 목록을 채우는 방법을 확신하지 못합니까? 나는 js에서 그것을 할 수 있었지만 PHP에서 어떻게 할 지 모른다. – Yahreen