3

I have a problem when returning REST spaces for a textarea from a list.

To get the information the REST is returning '↵' instead of space.

Need to know how I change this symbol '↵' for space.

Example: Image Erro: enter image description here

Image Correct: enter image description here

3
  • 1
    Could you provide the request and one of your result objects?
    – John-M
    Commented Oct 2, 2014 at 20:20
  • are you sure it's not a line break? Commented Oct 2, 2014 at 20:43
  • Well, I try to give a space in textarea but the rest returns the symbol. Check out the images below: Correct: i.imgur.com/cHE7vfU.png. Error: i.imgur.com/U4GiG2A.png
    – Renanfdo
    Commented Oct 2, 2014 at 20:47

1 Answer 1

3

It seems that string contains carriage return character in JSON result, in that case you could replace a carriage return character with a <br> using the following function:

function escapeCRLF(value) 
{
    return value.replace(/\r?\n/g, "<br />");  
}  

Example

Assume the following function is used for retrieving ListItem resource:

function getListItem(webUrl, listName,listItemId, complete, failure) {
    $.ajax({
        url: webUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + listItemId + ")",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            complete(data.d); 
        },
        error: function (data) {
            failure(data);
        }
    });
}

Then the following code demonstrate how to return escaped Description property:

getListItem(_spPageContextInfo.webAbsoluteUrl,listTitle,1,
function(data){
    var description = escapeCRLF(data.Description);
},function(error){
    console.log(JSON.stringify(error));
});

References

Special Symbols and Math Symbols in HTML and JavaScript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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