1
votes

I am using AJAX to GET JSON on a list in SharePoint 2013, I am successful in getting the information. My issue is in displaying said information. I get my array of 78 items to display, I also confirm the information by an Alert and the consoleenter image description here, but I have almost double that number of additional items being displayed with values of "undefined". I need assistance with figuring out why that is, and how to remove the excess items displayed. I am fairly new with using AJAX and REST so any assistance would be appreciated!

    function getData()
    {
        var $data = $('#data')
        $.ajax({
        type: "GET",
        dataType: "json",
        cache: false,
        url: "https://url.com/.../.../...",

        success: function(data)
        {

            console.log(data);
            alert("Data Loaded: " + JSON.stringify(data));
            $.each(data, function(index,item){
                $.each(this, function(index, item)
                    {
                    $data.append('<dl><dt> Event Date: </dt>' + item.EventDate + ' <dt>Subheading:</dt> ' + item.Subheading + '<dt> StatusInput: </dt>' + item.StatusInput + ' <dt> ReportIn: </dt>' + item.ReportIn + '<dt> Org: </dt>' + item.Org + '<dt> Start Reporting: </dt>' + item.StartReporting + '<dt> Stop Reporting: </dt>' + item.StopReporting + '<dt> Org Parent: </dt>' + item.OrgParent + '<dt> Modified: </dt>' + item.Modified + '</dl>');});
        });     
        }// end SUCCESS function
     });  
1

1 Answers

0
votes

So I would typically use a for-loop, but the code snippet below should help out. I suspect the reason you are getting two sets of results has to do with your nested $.each().

success: function(data){
    //Results are stored inside of the results object.
    var results = data.d.results;

    //Sometimes helps to log results to console. Helps
    //to see what the specific column names.
    console.log(results);

    $.each(results, function(index, item){

        //Try using your append here. 

    }
}