Paul
Paul

Reputation: 814

Populate textarea with special characters after jQuery GET request

When populating a textarea with special characters from a jQuery GET request, the special characters display as html codes. Eg. é rather than é.

The PHP file is outputting the text using htmlentities. Eg. echo htmlentities($text);

The pertinent part of jQuery request is here:

success:function(data){
     $('textarea').val(data);
}

Upvotes: 0

Views: 1572

Answers (3)

gdoron
gdoron

Reputation: 150253

Use Jquery html function instead of val:

success:function(data){
     $('textarea').html(data);
}

val will assign the "escaped" value, you want the HTML representation - html.

Watch this JSFiddle.

Upvotes: 1

Daria Trainor
Daria Trainor

Reputation: 5575

You can try this

$("button").click(function(){
    $("#test").val($("<div>").html(data).text());
});

Upvotes: 0

SpoonNZ
SpoonNZ

Reputation: 3829

success:function(data){
     $('textarea').html(data);
}

Does that work? Can't think, off the top of my head, but it should.

Upvotes: 2

Related Questions