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

在Mongodb中使用Ajax

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

    #reizen.w3-content.w3-container.w3-padding-64
        h3.w3-center REIZEN

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

    block content
    script.
        var i = 0;
        var x;
        displayCD(i);
        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);
            xmlhttp.send();
        }

        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) {
                i++;
                displayCD(i);
            }
        }
        function previous() {
            if (i > 0) {
                i--;
                displayCD(i);
            }
        }
  • 写回答

1条回答

      报告相同问题?

      悬赏问题

      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8