weixin_33726318 2019-12-05 21:29 采纳率: 0%
浏览 181


I've been looking for this for quite a while and I have no clue. I want to use Ajax to display information from a collection called 'reizen' in mondodb. I want to be able switch through all the elements from the collection and get all the information like the title etc. I have no idea how to get the information, I allready have a bit of code but I've been stuck for days, so I hope somebody can help me. If I only know how to get the title from each element from the collection 'reizen', I will be able to work further. (I copied some code from someone who used CD's but I want to do the same with 'reizen')

This is my code:

extends layout

block content

        h3.w3-center REIZEN

        input(type='button' onclick='previous()' value='<<')
        input(type='button' onclick='next()' value='>>')
        #showCD Here we will see all the elements of collection 'reizen'

    block content
        var i = 0;
        var x;
        function displayCD(i) {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    myFunction(this, i);
            xmlhttp.open("GET", "cd_catalog.xml", true);

        function myFunction(xml, i) {
            var xmlDoc = xml.responseXML;
            x = xmlDoc.getElementsById('showCD');
            document.getElementById('showCD').innerHTML =
            "Title:"  // get the title?

        function next() {
            if (i < x.length-1) {
        function previous() {
            if (i > 0) {
  • 写回答

1条回答 默认 最新

  • weixin_33724659 2019-12-06 16:54

    You are trying to use the data server-side. Your AJAX will work client-side. You can use Jade/Pug to create the container to hold your CDs, but you have to actually create the DOM elements client side using createElement, or React, or whatever other DOM API/wrapper you want.

    If you want all of this to be done server side, you don't want to do your AJAX in a script block that gets served to the client, you want to get the CDs programmatically within server-land and then pass the CD data to the Jade/Pug renderer server-side.

    You are trying to mix server-land and client-land and you need to pick one.




    • ¥15 如何利用闲置机械硬盘变现
    • ¥15 信号处理中的凸优化问题
    • ¥15 arm虚拟机无法和物理机互通
    • ¥15 如何在此代码上增加一个统计学生生源的功能?(语言-c语言)
    • ¥15 Android导航条遮盖异常
    • ¥15 计算机网络技术基础问题
    • ¥15 设置mac系统只能访问指定网站
    • ¥15 西门子博途 s7 1200控制三台步进电机
    • ¥15 基于非参数的方向距离函数求污染物影子价格(有偿)
    • ¥15 vue+element 生成table