I used REST API to get the Image form Picture Library and display my Banner Dynamically.
I used normal RESTful HTTP url like asusual Path and Query string param in the sequence of SELECT, FILTER and ORDER BY accordingly but I am not able to get "EncodedAbsUrl" in the result.
After I googled I got some idea, form some forums.
Like I used SELECT statement as a last querystring param, like below:
http://sharePointchild.com/_api/Web/Lists/GetByTitle('HomeBanner')/Items?filter=IsActive%20eq%201&$top=1&$orderby=IsActive%20desc&$select=EncodedAbsUrl
Code:
$(document).ready(function(){
var siteColUrl=_spPageContextInfo.siteAbsoluteUrl;
$.ajax({
method:"GET",
headers:{"Accept":"application/json; odata=verbose"},
url:siteColUrl+"/_api/Web/Lists/GetByTitle('HomeBanner')/Items?filter=IsActive%20eq%201&$top=1&$orderby=IsActive%20desc&$select=EncodedAbsUrl",
success: function (data) {
completeBannerdata(data);
}
,
error: function (error) {
failiureBannerdata(error);
}
});
})
function completeBannerdata(data)
{
var items = data.d.results;
if(items.length>0)
{
$('#imgBanner').attr('src', items[0]["EncodedAbsUrl"]);
}
}
function failiureBannerdata(error)
{
}
I used normal RESTful HTTP url like asusual Path and Query string param in the sequence of SELECT, FILTER and ORDER BY accordingly but I am not able to get "EncodedAbsUrl" in the result.
After I googled I got some idea, form some forums.
Like I used SELECT statement as a last querystring param, like below:
http://sharePointchild.com/_api/Web/Lists/GetByTitle('HomeBanner')/Items?filter=IsActive%20eq%201&$top=1&$orderby=IsActive%20desc&$select=EncodedAbsUrl
Code:
$(document).ready(function(){
var siteColUrl=_spPageContextInfo.siteAbsoluteUrl;
$.ajax({
method:"GET",
headers:{"Accept":"application/json; odata=verbose"},
url:siteColUrl+"/_api/Web/Lists/GetByTitle('HomeBanner')/Items?filter=IsActive%20eq%201&$top=1&$orderby=IsActive%20desc&$select=EncodedAbsUrl",
success: function (data) {
completeBannerdata(data);
}
,
error: function (error) {
failiureBannerdata(error);
}
});
})
function completeBannerdata(data)
{
var items = data.d.results;
if(items.length>0)
{
$('#imgBanner').attr('src', items[0]["EncodedAbsUrl"]);
}
}
function failiureBannerdata(error)
{
}