Question

Here's the deal. I'm trying to make a chat-like application that works with MySQL. Messages are stored in the database, and retrieved with JSON.

With .getJSON i print it to the div element which is used as a mailbox. I use 1s interval to check for messages and refresh. Here is the code which retrieves JSON:

setInterval(function() { 
    $.getJSON("inbox.php?<?php echo $_SESSION['connect']; ?>", function(data) {     
        if(data.length > 0) {
            var str = "";
            $.each(data, function(k, v) {               
                str += "<div class='inbox'>(" + v.time_trace + ") " + v.name + ": " + v.message + "</div>";
            });
            $("#messages").html(str);
        }
    });
}, 1000);

And it's all working fine, except...

When I send a unicode message, specifically a Cyrillic one, I get mojibake in Windows-1252 when jQuery uses that timer/interval. All the previous messages get garbled, until I refresh the whole page from the browser, and than it looks fine, shows UTF-8. That kinda looks like this:

�его� �ила ��п�ка.

If i disable the timer, and refresh myself I get good messages, but I need it to automatically check. HTML is set to UTF-8, and the DB is set to utf8_general_ci.

I really think that it has something to do with either getJSON, or something crazy like file encoding.

Thanks for your help.

Was it helpful?

Solution

I solved my problem by removing htmlspecialchars I've been using in another part of the code. That made the mess. Thank you for the markup strings note, I appreciate it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top