~~~~~~~~~Please check it and help~~~~~~~~~
我们正在使用 Javascript 更新该网站,以动态而不是静态加载 HTML,有菜单类别,我应该加载一个随机类别。大多数辅助功能已经为我编写好了,我只需要执行几行指令并执行在主页上加载随机菜单并访问外部 json 文件,其中菜单类别数据组织在使用 get.HTTP 请求的单独脚本文件。我将在下面输入 git 存储库链接,以便您可以检查我是否正确执行。
~~~~~~~~~~~~~~~~~~~~~~
chrome 开发者工具控制台错误消息显示:
**ajax.utils.js code snippet**
` // Makes an Ajax GET request to 'requestUrl'
ajaxUtils.sendGetRequest =
function(requestUrl, responseHandler, isJsonResponse) {
var request = getRequestObject();
request.onreadystatechange =
function() {
handleResponse(request,
responseHandler,
isJsonResponse);
};
request.open("GET", requestUrl, true);
request.send(null); // for POST only
};`
**JavaScript code snippet**
` document.addEventListener("DOMContentLoaded", function(event){
// On first load, show home view
showLoading("#main-content");
$ajaxUtils.sendGetRequest(
allCategoriesUrl,
[buildAndShowHomeHTML],
true);
});
// Builds HTML for the home page based on categories array
// returned from the server.
function buildAndShowHomeHTML(categories) {
// Load home snippet page
$ajaxUtils.sendGetRequest(
homeHtmlUrl,
function (homeHtml) {
var chosenCategoryShortName =
chooseRandomCategory(categories).short_name;
var homeHtmlToInsertIntoMainPage = insertProperty(homeHtml,
'randomCategoryShortName', '\'' + chosenCategoryShortName +
'\'');
insertHtml("#main-content", homeHtmlToInsertIntoMainPage);
},
false);
};`
//
''''''''''''''''''''''''''''''''''''''''''''''''''''
~~~~Source Link~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~