I am using this link for reference to fetch data from document library using Rest api.
The issue I am facing is I am getting junk data in result. Below is my code sample:
<button type='button' onclick="retriveItems()">Copy document</button>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type='text/javascript'>
function retriveItems() {
alert("Hello World");
var requesturi= "";
if((_spPageContextInfo.webAbsoluteUrl) && (_spPageContextInfo.webAbsoluteUrl.indexOf("sites")>0))
{
requesturi = _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFileByServerRelativeUrl('"+_spPageContextInfo.webServerRelativeUrl+"/Shared%20Documents/teghjhs.docx')/$value";
}
else
{
requesturi = _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFileByServerRelativeUrl('/Shared%20Documents/teghjhs.docx')/$value";
}
console.log(requesturi);
$.ajax
({
url: requesturi,
type: "GET",
headers:
{
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
},
cache: false,
success: function(data)
{
console.log('success');
console.log(data.d.results[0].Title);
},
error: function(data)
{
console.log('error occured');
}
});
}
</script>
Below is output screenshot when I hover on data or add it in console:
Can someone suggest me how can I get data in correct json output?