mercredi 19 novembre 2014

String Replace Line Feed from Ajax Response (TextArea)

Hi!

I've following problem.


I'm getting an ajax response from validating a textarea input.


I'm sending the input text to a SAP Server to validate it's correctness. It's being returned with the corrent '\n' line feeds. my problem is that the text in the text area doesn't break on the \n but the \n is display as text.



Code:



var val = value = field.getValue();
var params = {
value: val.toString()
};
Ext.Ajax.request({
url: url,
jsonData: JSON.stringify(params),
success: function(response, opts) {
var obj = JSON.parse(response.responseText);
var text = obj.VALOUT.toString(); //without toString() it isn't working too
text = String(sample).replace(/(?:\r\n|\r|\n)/g, '\n');
textarea.setValue(text);
}
}, this);

the Ajax.response would be something like that:


Code:



{"SUCCESS" :"true","MSGTEXT" :"","VALOUT" :"i am \\na\\nsample text"}

An in Chrome dev tools under preview:


I've build a fiddle with the same text as a string. This is working.

http://ift.tt/1EZeJgc


The text area is then displayed like:


Please help, me what i'm doing wrong.






String Replace Line Feed from Ajax Response (TextArea)

Aucun commentaire:

Enregistrer un commentaire