Jquery - convert ascii characters to HTML
I am reading data from a html file to be loaded into a div. The problem I am facing is that the program that writes the html files converts <br />
to<br />
SO when doing
$('#items').load('/News/list.aspx');
it displays <br />
as a string on my page rather than reading it as a page break.
I tried to read the above file into a variable to replace the string with <br />
, but doesn't seem to work.
Any suggestions?
a source to share
The first step would be to modify the server side of the script if possible so that the HTML doesn't get encoded in the first place.
Otherwise, you can use the method ajax
to load the page data into a string first. The method you are using just downloads the text immediately.
$.ajax({
type: 'GET',
url: '/News/list.aspx',
dataType: 'text',
success: function(response) {
response = response.replace( /</g, '<' );
response = response.replace( />/g, '>' );
$('#items').html(response);
}
});
Here I have replaced the individual angle brackets that convert everything back to HTML. If you only want line breaks and nothing else, replace those two lines withresponse = response.replace( /<br \/>/g, '<br />' );
a source to share
Is it url-encoded <and> tags?
Have you tried decoding the string you return with something like this?
http://plugins.jquery.com/project/URLEncode
NTN
EDIT: This is not url encoding, so it won't work.
a source to share