Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Dynamic Ajax Content charset problem

  1. #1
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dynamic Ajax Content charset problem

    Dynamic Ajax Content
    http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    When my external page includes characters like "ü,ö,ı", it seems like "?" (My external page has a meta tag "charset=windows-1254" in head section).

    When i search forum i see that

    I'm sure it should, but I'm afraid that's just not possible. A <meta> tag, not the best of ideas anyway, needs to go in the head; this AJAX script won't necessarily be able to write to the head.
    is there nothing to avoid this character problem?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Are you using named or number entities or the actual characters?

    The meta tags and anything else in the head section of the external page are lost with this script. You can load javascripts and/or css to the 'top' page for use with the external content using loadobjs(). If you need a meta tag for content on the external page, you could simply put it in the head on the 'top' page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for your reply.

    My top page has a meta tag like "charset=windows-1254" and also external page has same meta tag.

    I am using actual characters.I want to show rss feeds with this dynamic content.

    if it will avoid the problem i can replace characters with their named or number entities.(Edit:But i could not found the number entities of the characters like"ı,ğ,ş")
    Last edited by stormrider121; 07-03-2006 at 12:31 PM.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Any good ASCII to hex converter:

    http://centricle.com/tools/ascii-hex/

    will give you the hex value for a character, the above one precedes it with a % sign. Once you have the number, you can make a number entity for it. In the case of ğ it has a hex value of 11f, so your entity would be - &#x11f;

    This may or may not solve your problem though, worth a shot.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This didn't solve the problem.

    I have same problem with another Ajax script. Can we add a code to AJAX to write head part of external page?Please help.


    Ajax Tabs Content script

    http://www.dynamicdrive.com/dynamici...tent/index.htm

  6. #6
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If you'r using an external .php, use
    header('content-type: text/html; charset=YOURCHARSET');
    in the php-file.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I did a simple test here and it worked:

    http://home.comcast.net/~jscheuer1/side/ajax_h.htm

    Here are my two files:

    ajax_h.htm:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    
    /***********************************************
    * Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
    var loadedobjects=""
    var rootdomain="http://"+window.location.hostname
    var bustcacheparameter=""
    
    function ajaxpage(url, containerid){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e){
    try{
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch (e){}
    }
    }
    else
    return false
    page_request.onreadystatechange=function(){
    loadpage(page_request, containerid)
    }
    if (bustcachevar) //if bust caching of external page
    bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
    page_request.open('GET', url+bustcacheparameter, true)
    page_request.send(null)
    }
    
    function loadpage(page_request, containerid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(containerid).innerHTML=page_request.responseText
    }
    
    function loadobjs(){
    if (!document.getElementById)
    return
    for (i=0; i<arguments.length; i++){
    var file=arguments[i]
    var fileref=""
    if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
    if (file.indexOf(".js")!=-1){ //If object is a js file
    fileref=document.createElement('script')
    fileref.setAttribute("type","text/javascript");
    fileref.setAttribute("src", file);
    }
    else if (file.indexOf(".css")!=-1){ //If object is a css file
    fileref=document.createElement("link")
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", file);
    }
    }
    if (fileref!=""){
    document.getElementsByTagName("head").item(0).appendChild(fileref)
    loadedobjects+=file+" " //Remember this object as being already added to page
    }
    }
    }
    
    </script>
    </head>
    <body>
    <a href="javascript:ajaxpage('hex_h.htm', 'contentarea');">test</a>
    <div id="contentarea"></div>
    </body>
    </html>
    and hex_h.htm:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    </head>
    <body>
    &#x11f;
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I have the exact same problem. Cannot display greek characters in the external php file. In each page i have charset=utf-8 and all characters are being displayed right until i use the above script. In firefox and opera everything seems right, but in ie i see ?????????? in place of the greek word. I have this problem using either named or number entities of the characters. Adding header('content-type: text/html; charset=utf-8); to the php file didn't help. Any other ideas?

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    If using named entities isn't taking care of it, see:

    http://www.dynamicdrive.com/forums/s...8&postcount=14

    and the thread linked to it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Feb 2007
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I added AddDefaultCharset utf-8 to .htaccess file. I tested it locally (with wamp installed) and on my server. It still won't work in ie. Is there a way to modify the script to get this done? If not, any other ideas (or scripts)?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •