PDA

View Full Version : Dynamic Ajax Content Chars being replaced



AndyPiddock
07-21-2006, 01:26 PM
Dynamic Ajax Content

http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

Charactures being replaced.

Hi First thank's for all of the great scripts.

I'm using the dynamic content script and have a strange problem. The script does it's job of pulling content in but the resulting content if it includes a characture is replaced by a ? .

This is the page being pulled in http://www.hdweb.co.uk/kkpa/pages/content-about.html

notice the last char is a .

And here is the page it's being pulled into
http://www.hdweb.co.uk/kkpa/
Click on the About Us button.

The last char is now displayed as a ?:confused:

I'm using the same headers for both the target and content pages as below

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

Any ideas?

jscheuer1
07-21-2006, 02:49 PM
Try:

&#xa3;

instead of:


AndyPiddock
07-21-2006, 02:54 PM
Thanks John, yep can do this but the content page is editable by our client so they should be able to just type in

jscheuer1
07-21-2006, 03:26 PM
You're not from the states are you? I am, and I cannot just type in that character. The problem is that although you may have a keyboard mapped to produce that character and a key on that keyboard that has the symbol of that character on it, it is still (in the language of computers) a non-standard character. So, on the web, unless the page is served with the proper encoding, that character will not survive the trip from the server to the user's screen. When you add to this another layer to the process, as is done with dynamically added ajax content, things must go very well for the character to survive. As currently written, the ajax content scripts at Dynamic Drive make no provision for passing the dynamic content's Content-Type meta data to the server during the XMLHttpRequest process and in fact, this may not be possible. If it can be done, I am not aware of how to go about it. The server itself may be able to be configured to this.

Incidentally, you have another more serious problem with your example page. You have it coded to load into a division with the id of:

main_Content

but the id of that division is actually:

Main_Content

IE ignores this discrepancy and still finds the division in question. However, few if any other browsers will.

Twey
07-21-2006, 03:55 PM
&pound; is easier to remember.

AndyPiddock
07-24-2006, 08:37 AM
Thanks all so far for your replys.
:rolleyes:
Does anyone ahve the code I could use to convert a symbol read from the content page to &pound; when the page is viewed in Main_Content.

Twey
07-24-2006, 02:37 PM
In PHP:
$str = htmlentities($str);You should be doing this anyway, but evidently aren't. I suggest you use this.

If for some reason you can't, you'll have to do it in Javascript:
str = str.replace(/&#163;/g, "&pound;");

AndyPiddock
07-25-2006, 01:28 PM
Hi Twey,

Thanks. I'm obviously being a bit thick here:rolleyes:

Where exactly would i put the code?:confused:

Twey
07-25-2006, 02:43 PM
Find:
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.replace(/&#163;/g, '&pound;');
}Add the bit in red.

AndyPiddock
07-26-2006, 11:49 AM
Hi Twey. Really appcreciate your help here.

extract from my page.

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.replace(//g, '&pound;');

}


However have added the code as suggested which all makes sense to me and I see how this should work ... But it has no effect, the is still displayed as ?

:confused:

jscheuer1
07-26-2006, 05:18 PM
I wasn't going to say anything, in case it worked but - I didn't think it would. I figured that the &#163; character had already been stripped of its hex value by the process that created the variable 'page_request.responseText'. I also didn't say anything because I am not sure how to make the desired substitution before that process mangles the &#163; character. I'll have a look around to see if it might be possible though.

jscheuer1
07-26-2006, 06:49 PM
OK, since the responseText appears to be an intrinsic property of the page_request object, there really isn't any room for intervention there. You could use &pound; on the page to begin with, or there may be a way to configure the server to pass this character in the page_request object without stripping its high bit. I think mwinter had posted something about either doing this or about its not being possible. I will see if I can find that post.

AndyPiddock
07-27-2006, 10:26 AM
Thanks John,

Now using an alternative, but will keep comming back to see if there is a solution:cool:

jscheuer1
07-27-2006, 04:47 PM
OK, I looked for a post with that information yesterday but couldn't come up with effective search terms. Just now I hit upon the correct combination and found this post:

http://www.dynamicdrive.com/forums/showthread.php?t=3644

In it, mwinter (our 'semiretired' grandmaster problem solver) explains two methods to ensure that the host serves the document with the desired character encoding. Unfortunately, one of them - the .htaccess file method - may only work on an Apache server.

This was in response to a slightly different question so, a third solution was also offered - the meta tag solution. This we have already determined will not work in this case.

So, I would recommend that you try one or the other of the other two solutions. Either of these will actually configure the server to use that encoding, at least for your site. This is different from meta tag encoding which simply tells the user agent (browser) to use the desired encoding.

Now, I am not certain this will be a solution but, I think it might be and I'm fairly certain that if it is not, that there is probably no solution other than the &pound; entity or a different content management scheme (this is no law that says you must use Ajax for this).

petros
02-13-2007, 06:17 PM
I have problem with two characters:
,
I have fixed one , but I cannot use the replace tag for two characters. Anybody can me help?

I have try this:
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.replace(//g, '&aacute;');
}

but I need insert this too: (//g, '&oacute;');

:confused:

jscheuer1
02-13-2007, 06:38 PM
Replace is not a tag, it is a method. Whatever you call it, you can use it here as many times as you need it:


document.getElementById(containerid).innerHTML=page_request.responseText.replace(//g, '&aacute;').replace(//g, '&oacute;');

petros
02-13-2007, 06:45 PM
I have tryed this , Its don't work. I become only one replaced letter, this will replace generally &#225; &aacute;
the &#243; &oacute; is replaced too to &#225;

jscheuer1
02-13-2007, 06:55 PM
Try it again, make sure to do it just as I have shown.

petros
02-13-2007, 07:03 PM
The same.

You can see this here:
http://www.travel4lessholidays.com/details-En_Vacation_Resort_Italy_1_0.html

go to weather, click on the Limassol On the bolded text the letter &#243; is replaced with &#225;. This problem is only in linked text

jscheuer1
02-13-2007, 07:26 PM
This is what is in the file (ajaxtabs.js):


document.getElementById(containerid).innerHTML=page_request.responseText

on the server, no replacements attempted. And, from what I can tell from looking at the page, none are needed.

petros
02-14-2007, 03:22 PM
So thanks for help. I have make all the changes , but this will replace only one letter. And I become big problem, after the change my Ajax Tab didn't work in IE.

jscheuer1
02-14-2007, 03:44 PM
Well, I was going on the assumption that:



document.getElementById(containerid).innerHTML=page_request.responseText.replace(//g, '&aacute;');

At least worked for you for the a acute character. That is what you indicated in your first post, right?


I have problem with two characters:
,
I have fixed one , but I cannot use the replace tag for two characters. Anybody can me help?

I have try this:
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.replace(//g, '&aacute;');
}

but I need insert this too: (//g, '&oacute;');

:confused:

However, here in local testing just now, not even that worked. Also, if you are using IE 7 locally to test, there are separate issues with that not working. I would suggest just using the entities to begin with instead of trying to replace them during the loading of the external content.

petros
02-14-2007, 05:25 PM
I never use IE7 , all testings I make for IE 6. Before I have tested your tip, only in Firefox. After beginning the testing with IE, the Ajax didn't work. Thanks for help , but this is not a way.

jscheuer1
02-14-2007, 06:57 PM
Did you try the information in and linked to this post?

http://www.dynamicdrive.com/forums/showpost.php?p=45178&postcount=14