Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

Use Rest API to return link from sharepoint list

I'm trying to use REST API in SharePoint to getlistitems to display the link from a hyperlink field from my sharepoint list.

I AM successfully using the code to display the title field - but NOT the url from the hyperlink field.

I've tried appending the url in the code below with "/_api/web/lists/getbytitle('test')/items**?$select=URL**" without success.

<html>
<body>
<div>
<input type="button" id="btnSubmit" value="Get List Data using Rest API">
&nbsp;</div>
<div id="divResults" unselectable="on"></div>

<script src="/jquery.com/jquery-3.5.1.min.js" unselectable="on"></script>

<script unselectable="on">
$(function () {
$("#btnSubmit").on("click", function () {
getListData();
});
});
function getListData() {
var fullUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('test')/items";
$.ajax({
url: fullUrl,
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
},
success: onQuerySucceeded,
error: onQueryFailed
});
}
function onQuerySucceeded(data) {
var listItemInfo = '';
$.each(data.d.results, function (key, value) {
listItemInfo += '<b>Title:</b> ' + value.Title + '<br />';
});
$("#divResults").html(listItemInfo);
}
function onQueryFailed() {
alert('Error!');
}

</script>


</body>

</html>
question from:https://stackoverflow.com/questions/65599302/use-rest-api-to-return-link-from-sharepoint-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In onQuerySucceeded function, Try this line:

listItemInfo += '<b>UrlFromHyperLinkField:</b> ' + value.TestHyperLink.Url+ '<br />';

In my side, the HyperLink named "TestHyperLink", you can replace this field name with yours to make it work.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...