weixin_33734785 2019-01-15 13:41 采纳率: 0%
浏览 23

请求ajax findOne

i had a project contains many problems and i want to get one problem with findOne not all the problems in this project can someone correct for me my code.

this requete ajax which display for me all problems of this project

<div id="people"></div>
<script type="text/javascript">
   var data;
    var id = "<%= id %>";
     var problemes = [];
     $.ajax({
     url : "/projets/"+id+"/ajax",
     data : data,
      cache : false,
       dataType : "json",
        error : function(request, error) { 
       alert("Erreur : responseText: "+request.responseText);
     },
       success : function(data) {
      data = data.problemes;
         data.forEach(function(element) {
       var obj = {
         id: element._id,
         parentId:null,
         name:element.text
      }
     problemes.push(obj);
      });
        console.log('aa0', problemes);
      console.log('aa', problemes);
         var peopleElement = document.getElementById("people");
         var orgChart = new getOrgChart(peopleElement, {
        color: 'FF0000',
        primaryFields: ["name", "title"],
        photoFields: ["image"],
        dataSource: problemes
     });
     } 
      }); 
</script>

and this a route which returns a json data

router.get("/:id/ajax", function(req, res){
        Projet.findById(req.params.id).populate("problemes").exec(function(err, data){
            console.log("data", data);
           if(err){
              console.log(err);
           } else {
              res.status(200).json(data);
           }
        });

  });
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 python代码,帮调试
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条