2

I'm trying to get a field named Content from list which is of type RichHtml. When I try to get this using REST api call, I'm getting the content the html tags. How can I get the value only from this field using a rest api call ?

4
  • "The value" has HTML tags in it, that what makes it a RichHTML field (the possiblity to use tags) – Robert Lindgren Mar 17 '14 at 8:19
  • How can I get the data only from that field? without tags ? – Anish V Mar 17 '14 at 8:19
  • I think you can't, you will have to parse the value you get and strip out any tags with for example some javascript method – Robert Lindgren Mar 17 '14 at 8:25
  • 1
2

In jQuery .text() function allows to extract text content from Html.

Example:

var query = "/_api/web/lists/getByTitle('Pages')/getItemById(1)";
$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + query,
    type: "GET",
    headers: { "ACCEPT": "application/json;odata=verbose" },
    success: function(data){
      var pageContentText = $(data.d.PublishingPageContent).text();
      console.log(pageContentText);
    },
    error:  function(data){
      console.log(JSON.stringify(data));
    }
});

Your Answer

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

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