Digital Point Forums
Winn Law Group

Go Back   Digital Point Forums > Design & Development > Programming > PHP
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Jan 5th 2009, 5:16 am
NoamBarz NoamBarz is offline
Champion of the Naaru
 
Join Date: Apr 2007
Location: Israel
Posts: 201
NoamBarz is on a distinguished road
Question PHP/ Ajax Question

I need to load some information from a mysql database using ajax. The db table charset and collation are set to utf8.

here's my ajax function:
Code:
//-------------------------------------------------------------------------------------------------------
function DisplayContent(httpRequest, element) { 
        var elem = document.getElementById(element);
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
	             elem.innerHTML = httpRequest.responseText;
	             return;
            } else {
                alert('There was a problem with the request.');
            }
        }
}
//-------------------------------------------------------------------------------------------------------

var httpRequest;

//-------------------------------------------------------------------------function makeRequest(url, element) {
        	
        //var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP.5.0"); //new ActiveXObject("Msxml2.XMLHTTP");
                } 
                catch (e) {
                           try {
                                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                           } 
                           catch (e) {}
               }
        }   

        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }

        httpRequest.onreadystatechange = function() { DisplayContent(httpRequest, element); };
        httpRequest.open('GET', url, true);
        httpRequest.send(null);

}
//-------------------------------------------------------------------------

so using javascript, in order to dump db info into an HTML elementy, all Ineed to so is supply the url of the page that will select the data and the element in which it should display the data.

My problem has to do with the encoding. my php file - the one that selects the data is saved in utf-8 format. if I assign a varraible a value in hebrew, it will display just fine on the HTML page. When I select a record from my table however, it doesn't dislpay properly - I get jibberish.

I use $result=mysql_query("SET NAMES 'utf8'"); but that doesn't help either.

does anyone know what's going on? writing actual text in the code should guarantee that it is formatted in utf-8. Since data from the db won't display, does that mean it is somehow not in utf-8?
__________________
דפוס, בית דפוס,
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX Love Calculator - Web 2.0, AJAX, Clean, PHP Script - $15.00 craze3 Content 28 Dec 30th 2009 3:31 pm
Good JS/Ajax Libraries - and running PHP functions from Ajax. blueparukia JavaScript 4 Aug 12th 2008 9:16 am
Ajax inline editor [ AJAX / PHP / MYSQL ] [Free] ! pitttih Programming 2 Jan 14th 2008 2:51 am
Ajax , php Question mohajer PHP 8 Jan 4th 2008 6:39 am
Php Echo or include problem? (PHP / AJAX) Neo_The_One PHP 6 Jan 26th 2007 7:30 am


All times are GMT -8. The time now is 1:52 pm.