Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

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


Go to End


4 Posts   4059 Views

Avatar
joelg

Community Member, 134 Posts

28 August 2009 at 8:24am

Edited: 28/08/2009 8:27am

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?

Avatar
joelg

Community Member, 134 Posts

28 August 2009 at 9:12am

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.

Avatar
dalesaurus

Community Member, 283 Posts

28 August 2009 at 9:58am

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

Avatar
joelg

Community Member, 134 Posts

28 August 2009 at 7:29pm

Ok, thanks for the reply...