Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load jQuery charset

Tags:

jquery

php

I hava 2 php files. index.php and preview.php

in the top of index.php I have this code

<meta http-equiv='Content-Type' content='Type=text/html; charset=utf-8'>

When I try to load content to index.php from preview.php using:

function preview_content(id)
{

    var thebutton = '#previewButton';
    $(thebutton).hide();
    $('#preview_area').load('preview.php?id='+id);
}

the content loaded with characters like this M�laga CF

I tried to put the same utf-8 code in the top of preview.php but nothing changed. Is there any way to retrieve the content with UTF-8 charset?

like image 540
Othman Avatar asked Aug 15 '26 19:08

Othman


1 Answers

Please be sure about preview.php's encoding is UTF-8. Your editor's default encoding applies newly created files but if you copied preview.php from somewhere else it's encoding might be different. Also adding header('charset=utf-8'); as first line to preview.php might help. Like this;

<?php
header('charset=utf-8');
// your code below here
.
.
.

You can also use .ajax() and specify contentType instead of .load();

function preview_content(id)
{

    var thebutton = '#previewButton';
    $(thebutton).hide();
    $.ajax({
        data: { "id" : id },
        type: "GET",
        url: "preview.php",
        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
        success: function(output) {
            $('#preview_area').html(output);
        }
    });
}
like image 100
Emre Erkan Avatar answered Aug 18 '26 11:08

Emre Erkan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!