Using XMLHttpRequest to save raw HTML

Workarounds and usability notes.

Using XMLHttpRequest to save raw HTML

Postby John Robin Dove » Thu Dec 11, 2014 10:27 am

Hi,

I'm retrieving raw HTML (at least I think that's the correct definition) from an embedded CKEditor instance using the CKEditor function getData() as explained here: http://docs.ckeditor.com/#!/guide/dev_savedata. I send it from the editor to a Toolbook field which sends it to the server using XMLHttpRequest on property change. I save it as if it were a text file. I thought this system was OK. (As I mentioned previously elsewhere, on my server, the php file needs to use the php stripslashes function to avoid extra slashes appearing.) However there is another problem: the ampersand character prevents the complete text being saved. Only the text before the first occurrence of an ampersand is saved. I have overcome this by using pgReplace to convert all ampersand characters to the rarely used international monetary symbol ¤ (ansi 164) because it doesn't even exist on a number of keyboards including British and American. I can put the text back into the CKEditor by using the process in reverse all ¤ characters are set back to &.

Should I be using encodeUriComponent to do this? I'm not quite sure how this works. If not, the system described above seems pretty good but are there any other 'rogue' caharacters like the ampersand? And is there a better choice of replacement character than ¤?
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Using XMLHttpRequest to save raw HTML

Postby Clifton » Thu Dec 11, 2014 12:27 pm

To guarantee your query string reaches your server as expected, use encodeURIComponent().

To exeute this query:
server.php?title=My name is Frank & my last name is Jones

Try this actions editor code:
encodeURIComponent( "My name is Frank & my last name is Jones" ); store return value in myQuery
set myQuery to "server.php?title=" & myQuery

Should give you this query string:
server.php?title=My%20name%20is%20Frank%20%26%20my%20last%20name%20is%20Jones

This is a safe string for make XMLHttp posts.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Using XMLHttpRequest to save raw HTML

Postby John Robin Dove » Thu Dec 11, 2014 2:04 pm

Thanks Clifton but I can't get it to work. I'm still losing any text that follows an ampersand. I have put the file contents here http://www.mediacours.com/tb_examples/raw.txt. If I use the pgReplace system described above to remove and replace the ampersands everything else works: paragraphs, colors, fonts, foreign characters etc.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Using XMLHttpRequest to save raw HTML

Postby John Robin Dove » Thu Dec 11, 2014 2:07 pm

I notice the Chinese characters have somehow got lost after the txt file was sent to my server. This is not important because in my app they are saved correctly.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Using XMLHttpRequest to save raw HTML

Postby John Robin Dove » Thu Dec 11, 2014 2:30 pm

Correction: encodeURIComponent is functioning correctly in another test application I have made but not in my pad application. I don't know why.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Using XMLHttpRequest to save raw HTML

Postby John Robin Dove » Thu Dec 11, 2014 3:04 pm

Now I know why! :D There was an error in my action sequence. The encoded string was discarded instead of being placed into the appropriate variable. Sorry to have wasted your time.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Using XMLHttpRequest to save raw HTML

Postby Clifton » Thu Dec 11, 2014 4:06 pm

Glad it is working!!!
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 5 guests

cron