0

I using the code below, but and the script that creates the folder on my SP online server is working just fine, but the problem is that return data is undefined

$.when(pCreate(path + "/" + name)).always(function (data) {
    console.log("data");
    console.log(data);
});
var pCreate = function (pathAndName) {
    getFormDigest(pageContent.web.absoluteUrl).then(function (data) {
        $.ajax({
            "url": pageContent.web.absoluteUrl + "/_api/Web/Folders/add('Shared Documents" + CustomerStartingFolder + pathAndName + "')",
            "type": "POST",
            "headers": {
                "accept": "application/json; odata=verbose",
                "content-type": "application/json; odata=verbose",
                "X-RequestDigest": data.d.GetContextWebInformation.FormDigestValue
            }
        });
    });
}

Can someone point out what is wrong since I dont get the return data of the created folder?

1
  • 1
    pCreate seems to not have a callback method from the ajax call Jun 20, 2018 at 12:25

1 Answer 1

1

As Robert stated, AJAX is async and returns data via a callback method. Something like this:

$.ajax(
{
    "url": "/sites/yourSite/_api/Web/Folders/add('Shared Documents/TestFolder')",
    "method": "POST",
    "headers": {
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
        "content-length": 0,
        "X-RequestDigest": "yourRequestDigestGoesHere"
    },
    "success" : function(data){ alert(JSON.stringify(data, undefined, 4)) },
    "error" : function(err){ alert(JSON.stringify(err, undefined, 4)) }
}
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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