1

I have this code bellow:

jQuery.ajax({
                url: "https://test.sharepoint.com/sites/test/Negocio/_api/web/Folders('Historico')/Folders",
                method: "GET",
                headers: {
                    "Accept": "application/json; odata=verbose" 
                },
                success: function (data) {
                    console.log(data);
                },
                error: function (error) {
                    console.log(error);
                }
            });

The code returns all subfolders, I want to insert for each subfolder the properties like title, created in this code:

<div id="SubFolders">
    <div>
        <label>SubFolder Title</label>
    </div>
    <div>
        <p>Something else...</p>
    </div>
</div>

Can someone help me?

2

Sample code for your reference:

    <script src="https://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
    <script type="text/javascript">

    function getfolders() {
    $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/folders('doc1')/folders",
            type: "GET",
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
            },        

            success: onQuerySucceeded,
            error: onQueryFailed
        });

    }

    function onQuerySucceeded(data) 
    {
          console.log(data.d.results);
           $.each(data.d.results, function (key, value) {
           $("#SubFolders").append("Folder Name: "+ value.Name+"<br/>");
           $("#SubFolders").append("Folder Created Time: "+value.TimeCreated+"<br/>");


          });
    }

    function onQueryFailed() {
        alert('Sorry An Error Has Occurred!');
    }
     $(function() {
     ExecuteOrDelayUntilScriptLoaded(getfolders, "sp.js");

    });

    </script>
<div id="SubFolders">

</div>

enter image description here

  • Hello, is giving me undefined instead of name and data. – KmDroid Jan 16 at 16:39
  • What you got from console.log(data.d.results); check the browser Developer Tool by clicking F12 – Jerry_MSFT Jan 17 at 10:19

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.