0

How do I get my SharePoint Rest API Results to return like so:

Title : FDA Project RioBravo
Module: Primary Training
Roles : Project Manager, Lead Agent

versus the way this returns them like so:

Title : FDA Project RioBravo Module: Primary Training Roles : Project Manager, Lead Agent

<script type="text/javascript">
$.ajax({
url: "https://gumdropsgc.sharepoint.com/sites/Training/_api/web/lists/getbytitle('Modules')/items?$filter=File_x0020_Name Eq 'FDAAgents'&$top=1",
type: "GET",
headers: {"Accept": "application/json;odata=verbose"},
cache:false,                
success: function(data){
console.log(data);
var items = [];
$(data.d.results).each(function(){
items.push('<ul id="' + 'listUL' + '">' + 
'<li id="' + 'listLI' + '">' + 
this.Title  +
'</li>' + 
'</ul>');
});
items.push("</div>");
$("#listResult").html(items.join(''))}
});
</script>

<div id="listResult"></div>
0

Try this

<script type="text/javascript">
$.ajax({
    url: "https://gumdropsgc.sharepoint.com/sites/Training/_api/web/lists/getbytitle('Modules')/items?$filter=File_x0020_Name Eq 'FDAAgents'&$top=1",
    type: "GET",
    headers: {"Accept": "application/json;odata=verbose"},
    cache:false,                
    success: function(data){
        console.log(data);
        var html = "<table border='0'>";
        $(data.d.results).each(function(){
            html = html + "<tr><td>" + this.Title + "</td></tr>";
        });
        html += "</table>";
        $("#listResult").html(html)
    }
});
</script>

<div id="listResult"></div>
2
  • Amal - Thanks! This worked great. It allowed me to pull the list items I needed and display them accordingly. – Bitspider Jan 14 '15 at 17:53
  • @Bitspider nice to hear it worked for you! – Amal Hashim Jan 14 '15 at 17:56
0

You an also try this:

<script type="text/javascript">
$.ajax({
url: "https://gumdropsgc.sharepoint.com/sites/Training/_api/web/lists/getbytitle('Modules')/items?$filter=File_x0020_Name Eq 'FDAAgents'&$top=1",
type: "GET",
headers: {
    "accept": "application/json;odata=verbose",
},              
success: function(data){
console.log(data.d.results.length); 
    $.each(data.d.results, function (index, item) {
        var html = "<table border='0'>";
    html = html + "<tr><td>" + item.Title + "</td></tr>";   
});
    html += "</table>";
    $("#listResult").html(html);
},
    error: function (error) {
        console.log("Error");
    }
});
</script>
<div id="listResult"></div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.