Jquery json releases special characters

So, I'm working on a system to get a meta tag from a web page to get information about embedding a video from a link (like facebook).

I also get a page title and description to fill in some fields. And here I have a problem, the description works fine, because it is a text field, so I can use it .html(), but the title is input, so I can either use .attr()or .val(), and the problem arises from special characters like (é à è ö ä ü) .

Here is my code that I use.

This is my jQuery script action:

<script type="text/javascript" charset="utf-8">     
$(function(){
    $("#url").bind("change", function(){
        var url = $("#url").val();
        $.getJSON("/ajax/embed_video.php", { url: url }, function(json) {
            $(json.embed).appendTo("#feeds");
            $("#title").attr("value", json.title);
            $("#description").html(json.description);
         });
    });
});
</script>

This is my php file for exporting JSON data:

$url = $_GET['url'];
$result = getUrlData($url); //this get the metadata from the url
$description = $result['metaTags']['og:description']['value'];
$title = $result['metaTags']['og:title']['value'];

$img_name = basename($result['metaTags']['og:image']['value']);
copy(''.$result['metaTags']['og:image']['value'].'', "../".$path_video_temp.$img_name);

$embed = " "; //EMBED CODE

$data = array('title' => $title,'description' => $description, 'embed' => $embed, 'img' => '/'.$path_video_temp.$img_name);

header('Content-Type: application/json; Charset=UTF-8');
echo json_encode($data);

When I have a headline with any accent or any special character, it prints &eacute;, etc.

html_entity_decode htmlspecialchars_decode

, - , .

+3
1

Ajax , getjson Ajax, , Ajax getjson

http://api.jquery.com/jQuery.getJSON/

Ajax

http://api.jquery.com/jQuery.ajax/

, json , Ajax async false

--- Edit ---

jsonp, ?

--- 2 ---

?

HTML jQuery?

, !

+1

All Articles