Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Ajax – special characters (æ, ø & Ã¥) makes jQuery.load break

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2680 Views
  • joelg
    Avatar
    Community Member
    129 Posts

    Ajax – special characters (æ, ø & å) makes jQuery.load break Link to this post

    Hi

    I have a normal ajax-function that works fine. It executes with this jquery-code in the template:

    <a href="#" onclick="jQuery('#ajaxContent').load('http://localhost:8888/mysite/kontakt/erstatBillede/299'); return false;">

    And the php-code also works fine:

    function erstatBillede()
       {
           if($this->isAjax)
          {
             $BilledeID = Director::urlParam("ID");
             $Billede = DataObject::get_one("BilledeObject", "BilledeID = $BilledeID");
             
             return $Billede->renderWith("ajaxSnippet");
          }
          else
          {
              return Array();
          }
       }

    And at last the code for the ajaxSnippet:

    <% control Billede %>
       <a href="$URL" class="group" title='$Title' rel="galleri">
          <img class="thumb" src="<% control SetWidth(360) %>$URL<% end_control %>" alt='$Title'/>
       </a>
    <% end_control %>

    $HTMLBeskrivelse

    Now the problem is the HTMLTextfield: $HTMLBeskrivelse - this is plain html-code made in a SimpleTinyMCEField in an object powered by the DataObjectManager module. All of this also works fine, except when I use special characters like æ, ø and å in danish.

    I've checked my database and it uses UTF-8 just like the html-template, so I guess that shouldn't be the problem.

    If I change $HTMLBeskrivelse from "HTMLTextfield" to "Textfield" then I get raw html code out into the template. For some reason it just doesn't work as html-text.

    I've also done a ContentNegotiator::disable(); in _config.php, but this doesn't make any difference.

    Can anyone help?

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: Ajax – special characters (æ, ø & å) makes jQuery.load break Link to this post

    Found a solution on this problem. I've been using ZendAMF to retrieve some data from Silverstripe to ActionsScript 3 and I remember having a similar problem. So I used this PHP function called html_entity_decode, which apparantly also helped with my AJAX problem:

        function erstatBillede()
        {
           if($this->isAjax)
          {
             $BilledeID = Director::urlParam("ID");
             $Billede = DataObject::get_one("BilledeObject", "BilledeID = $BilledeID");
             $Billede->HTMLBeskrivelse = html_entity_decode($Billede->HTMLBeskrivelse, ENT_NOQUOTES, "UTF-8");
             return $Billede->renderWith("ajaxSnippet");
          }
          else
          {
              return Array();
          }
       }

    If you have any insight on this issue please post and share.

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Ajax – special characters (æ, ø & å) makes jQuery.load break Link to this post

    Unfortunately this is the sad reality that is UTF-8 compliance. Decoding/Encoding the entities with php's built in functions as you are doing might be the best option. You might also give shot with iconv for comprehensive language set conversion:

    http://us3.php.net/manual/en/function.iconv.php

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: Ajax – special characters (æ, ø & å) makes jQuery.load break Link to this post

    Ok, thanks for the reply...

    2680 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.