Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 递归ajax查询_Javascript_Jquery_Ajax_Sharepoint_Datatables - Fatal编程技术网

Javascript 递归ajax查询

Javascript 递归ajax查询,javascript,jquery,ajax,sharepoint,datatables,Javascript,Jquery,Ajax,Sharepoint,Datatables,我希望有人能给我一个如何实现以下目标的指针 目前,我有: JS函数:一个jQuery AJAX查询,它将从SharePoint自定义列表中获取项目 JS函数:它将把列表结果放入datatable 一个JS函数,可以将inittorID转换为用户的真实名称(GetDisplayName) 简言之,实现我的目标最好的方法是什么 非常感谢 格伦我不确定我是否完全理解你的问题,因此这里是我对情况的最佳猜测(如果我错了,请纠正我) 进行AJAX调用以从SharePoint自定义数据库获取项目列表 列表,

我希望有人能给我一个如何实现以下目标的指针

目前,我有:

  • JS函数:一个jQuery AJAX查询,它将从SharePoint自定义列表中获取项目

  • JS函数:它将把列表结果放入datatable

  • 一个JS函数,可以将inittorID转换为用户的真实名称(GetDisplayName)

    简言之,实现我的目标最好的方法是什么

    非常感谢
    格伦

    我不确定我是否完全理解你的问题,因此这里是我对情况的最佳猜测(如果我错了,请纠正我)

  • 进行AJAX调用以从SharePoint自定义数据库获取项目列表 列表,但遗憾的是,此列表中的一列具有inittorID而不是用户名
  • 为了解决这个问题,我们需要进行另一个AJAX调用,该调用将为我们刚刚检索到的一组匹配的inittorid获取一个用户名列表
  • 一旦我们有了它,我们想把数据放在一个数据表中显示
  • 在不知道细节的情况下,我只会进行嵌套的AJAX调用。基本上,第一次调用完成后,调用第二个AJAX函数。完成该操作后,更新dataTable。比如:

    $.ajax({ 
        url: MY_FIRST_URL,
        data: myFirstData
    }).done(function (data) {
        // The first call gets completed after some time and the 'done' function is called.
        // here, extract the various InitatorID values, and pass them to the
        // second AJAX call, so you can then get the usernames for those Ids
    
        var initatorIds = // ... do data massaging here to get the initatorIds 
                          // into the format you want from the 'data' variable
                         //  passed in the done function...
    
        $.ajax({ 
            url: MY_SECOND_URL,
            data: initatorIds 
        }).done(function (data2) {
            // once the SECOND call is complete, populate the dataTables
    
            var jsonData =  // ... some manipulation of data and data2 results
                            // to get the combined output you want. 
    
            $("#resultsDivMyOutstandingItems").dataTable( {
                  "data" : jsonData,
                   columns: [
                   ....
                   ....
            }); 
        }).fail(function (jqXHR, textStatus) {
            // do stuff if the second call fails
        }); 
    }).fail(function (jqXHR, textStatus) {
       // do stuff if the first call fails
    });
    

    冒着使解决方案过于复杂的风险,我个人希望通过dataTable插件中的ajax功能将数据直接加载到表中(请阅读更多相关信息)。但如果它能将混乱降到最低,那么一定要先这样做

    太好了,谢谢你!我使用了嵌套ajax的思想。今晚我将发布我的完整解决方案。希望它能有所帮助!如果答案确实对您有帮助,请记住将其标记为正确,祝您好运!
          var request = $.ajax({
            url: queryUrl,
            type: "POST",
            data: JSON.stringify(requestData),
            headers: {
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "Accept": "application/json; odata=verbose",
                "Content-Type": "application/json; odata=verbose"
                    }
            }),
            chained = request.then(function( data ) {
                return $.ajax( spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + data.InitatorId + ")",
                { data: { user: data.Title }} )
            });
    
            chained.done(function( data ) {
              console.log(data)
            });
    
    $.ajax({ 
        url: MY_FIRST_URL,
        data: myFirstData
    }).done(function (data) {
        // The first call gets completed after some time and the 'done' function is called.
        // here, extract the various InitatorID values, and pass them to the
        // second AJAX call, so you can then get the usernames for those Ids
    
        var initatorIds = // ... do data massaging here to get the initatorIds 
                          // into the format you want from the 'data' variable
                         //  passed in the done function...
    
        $.ajax({ 
            url: MY_SECOND_URL,
            data: initatorIds 
        }).done(function (data2) {
            // once the SECOND call is complete, populate the dataTables
    
            var jsonData =  // ... some manipulation of data and data2 results
                            // to get the combined output you want. 
    
            $("#resultsDivMyOutstandingItems").dataTable( {
                  "data" : jsonData,
                   columns: [
                   ....
                   ....
            }); 
        }).fail(function (jqXHR, textStatus) {
            // do stuff if the second call fails
        }); 
    }).fail(function (jqXHR, textStatus) {
       // do stuff if the first call fails
    });