Когда я запускаю свой код, он дает мне ошибку «ReferenceError: MyVariable не определен» на var comm_Id, я пытаюсь получить идентификатор страницы, а затем сгенерировать URL-адрес для вызова rest APIReferenceError: MyVariable не определен
Этот "$ {community.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>
Из какой библиотеки этот синтаксис? '$ {Community.id}'? Вероятно, следует пометить его – CodingIntrigue
Это, вероятно, язык выражений из java JSP. – vdubus
Это также верно PHP, я думаю (внутри строк с двойными кавычками или HEREDOC). –