当我运行我的代码时,它在 var comm_Id 上给我一个错误“ReferenceError: MyVariable is not defined”,我正在尝试获取页面 ID,然后生成 URL 以调用其余 API
这个 "${community.id}" 动态获取页面的 ID。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var comm_Id = ${community.id} //MyVariable being the supposed ID of the page
var cat_id = ${coreNode.ancestors[0].id}; //Category ID of the boards parent
var restUrl = "/"+comm_Id+"/restapi/vc/categories/id/"+cat_id;
$.ajax({
type: "GET",
url: restUrl,
contentType: "text/xml; charset=utf-8",
data: "DATA",
success: function (response) {
var index = 0;
var fltBoardID = "";
var boardId="";
var categoryNode = $(response).find("category > title");
var categoryTitle = $(categoryNode).text();
$("#category-title").html("<p>More in the "+categoryTitle+" category</p>");
$(response).find("board > id").each(function () {
boardId = $(this).text();
var boardTitle = $(response).find("board > title:eq("+index+")");
var otherBoardsList = $(boardTitle).text();
$("#Other-Boards-List").append("<ul><li><a href='"+"/t5/board/bd-p/"+boardId+"'>"+otherBoardsList+"</a></li></ul>");
index++;
});
},
error: function (response) {
$('#Other-Boards-List').html('Failed to load the content');
}
});
});
</script>
<div id="Other-Boards-List">
<div id="category-title"></div>
<p style="font-size:18px;">Browse other boards</p>
</div>