0

我正在查询 salesforce 数据库以获取一些数据。查询结果将在一个响应中返回最多 2000 条记录,并且还将返回“nextRecordsUrl”参数,我们可以使用该参数获取下一组结果。所以我可以通过在 $.ajax() 的 done 函数中再次调用相同的方法来实现这一点。我想知道是否有更好的方法来做到这一点?

function stringSearch(queryParam){
    var sessionCookie = getCookie('sid');
    var currentDomain = window.location.host;

        queryParam = queryParam== undefined || queryParam =='' ? "/services/data/v28.0/query/?q=SELECT+Name+from+Account" : queryParam;
        $.ajax({
            url : "https://"+currentDomain+queryParam,
            headers : {"Authorization": "Bearer "+ sessionCookie},
            contentType : "application/json"
        }).done(function(res){
            //do some processing with the result
                    processingFunction(res.records);
            if(res.nextRecordsUrl){
                //call the same method with different parameters
                stringSearch(res.nextRecordsUrl);
            }else{
                //Done with all the processing proceed to final actions 
            }
        }).fail(function(err){
            alert('Oops!! We were unable to fetch the data you requested!\n'+JSON.stringify(err)+'\n ');
        });
 }

 function processingFunction(){
    //use the array and do some processing. 

 }
4

0 回答 0