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

  • 1
    Could you provide the request and one of your result objects? – John-M Oct 2 '14 at 20:20
  • are you sure it's not a line break? – Derek Gusoff Oct 2 '14 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 Oct 2 '14 at 20:47
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

| improve this answer | |

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.