0

I am trying to create a text file in alibrary named "testRestDocs" The dev tool console the following error message:

_spPageContextInfo.webAbsoluteUrl + "_api/web/getfolderbyserverrelativeurl('/s/KM/box/pg/testRestDocs')/Files/add(url='" + docTitle +"',overwrite=true)"; 

$(function () {
 bindButtonClick();
});
function bindButtonClick() {
 $("#btnSubmit").on("click", function () {
   createDocument();
 });
}
function createDocument() {
 var docTitle = $("#txtDocumentTitle").val() + ".txt";
 var docContent = $("#txtDocumentContent").val();
 var fullUrl =  _spPageContextInfo.webAbsoluteUrl + "_api/web/getfolderbyserverrelativeurl('/s/KM/box/pg/testRestDocs')/Files/add(url='" + docTitle +"',overwrite=true)";
 $.ajax({
   url: fullUrl,
   type: "POST",
   data: docContent,
   headers: {
     "accept": "application/json;odata=verbose",
     "content-type": "application/json;odata=verbose",
     "X-RequestDigest": $("#__REQUESTDIGEST").val()
   },
   success: onQuerySucceeded,
   error: onQueryFailed
 });
}
function onQuerySucceeded() {
 $("#divResults").html("Document created!");
}
function onQueryFailed() {
 alert('Error!');
}

Your Answer

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

Browse other questions tagged or ask your own question.