s0-0s
s0-0s

Reputation: 144

Special characters doesnt work when load a page into div by ajax

I'm trying to change my static php page to ajax. I don't have much information about it to be honest.

My problem is: When I load content into a div, my old php version works fine but when i use the ajax to get content into a div(that i found actually, you can find below) italian characters turns to �.

I browsed some other similar questions but I couldnt find useful information.

I use the header:

my sql coding is utf_unicode_ci

and I also realized when i add php header as utf 8, my php version characters brokes too.

I appriciate any kind of suggestions

Thanks

<script>

function createRequestObject() 
{
    var returnObj = false;

    if(window.XMLHttpRequest) {
        returnObj = new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        try {
            returnObj = new ActiveXObject("Msxml2.XMLHTTP");

            } catch (e) {
            try {
            returnObj = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {}
            }

    }
    return returnObj;
}

var http = createRequestObject();
var target;

// This is the function to call, give it the script file you want to run and
// the div you want it to output to.
function sendRequest(scriptFile, targetElement)
{   
    target = targetElement;
    try{
    http.open('get', scriptFile, true);
        }
    catch (e){
    document.getElementById(target).innerHTML = e;
    return;
    }

    http.onreadystatechange = handleResponse;
    http.send();    
}

function handleResponse()
{   
    if(http.readyState == 4) {      
    try{
        var strResponse = http.responseText;
        document.getElementById(target).innerHTML = strResponse;
        } catch (e){
        document.getElementById(target).innerHTML = e;
        }   
    }
}
</script>

Upvotes: 0

Views: 170

Answers (1)

event
event

Reputation: 379

It would probably be the best if you use utf-8 for both your page and your ajax response. You could also try using '&#;'-notation for non-ascii characters.

Upvotes: 1

Related Questions