I am looking to return a files contents and I am using a webservice and JSON to do this.
I have managed to return the contents but it is not in the format I want it to be in.
I need the top text area to be in the same format as the textarea on the bottom:
I need to to display the \n
as a new line rather than just remove it from the string.
Current code (ignore alerts, only for my own testing purposes):
function CallWebService(CSSFile) {
var stringToDisplay = "";
var webMethod = "../services/BrokerAdmin/CSSComparison.asmx/GetFileContents";
$.ajax({
type: "POST",
async: false,
url: webMethod,
data: JSON.stringify({
CSSFile: CSSFile
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {},
error: function(e) {
alert("Error = " + e.responseText);
},
complete: function(msg) {
alert(msg);
if (JSON.parse(msg.responseText).d.toString() != "" || JSON.parse(msg.responseText).d.toString() != null) {
alert("msg.responseText = " + msg.responseText);
$('#ctl00_BodyContent_elm2').val(msg.responseText);
} else if (JSON.parse(msg.responseText).Message.toString() == "" || JSON.parse(msg.responseText).d.toString() == null) {
alert("YOU LOSE!");
} else {
alert("TRY AGAIN");
}
}
});
}
Can anyone help?