tags:

views:

24

answers:

2

I'm creating a WYSIWYG editor that saves the page via AJAX.

How it works is you add your elements (text, images, etc) to a DIV via the editor, and when you click "save", it sends that DIV's HTML through AJAX to a script that takes this HTML and writes it into "index.html", so it'll update the front page.

My problem: if the DIV has a background image, the AJAX page screws up. Something to do with all the quotes is my guess (<div style="background-url('picture.png');">). It handles everything else fine (images, text with both single and double quotes, etc).

I was looking through Firebug, and it's reporting that it's changing the 'picture.png' to &quot;picture.png&quot;. I've tried replacing the &quot; before it sends, but it's still breaking on the other end from all the quotes.

Does anyone have any idea?

A: 

try dumping it server side - i'd expect its something to do with URL encoded (i.e. % encoded) quotes and/or your server side software adding backslashes

tobyodavies
A: 

What language is handling your AJAX on the other end? If it's PHP, check out htmlentities(). Also, the ampersand (&) has broken my ajax requests in the past.

Steve
It is PHP. If I check the output from Firebug it tells me it sent with the "s around it. If I check the input at the other end (the PHP AJAX receiving side), it gives me broken code in the $_POST array.
Jordan
Did you try escaping the quotes with backslashes? \' Or, hard-code the entity...here's something that might help: http://htmlhelp.com/tools/validator/problems.html
Steve
I don't know why that never occurred to me. It was definitely the ampersands in " screwing it up. I tried it earlier, but I accidentally forgot to replace all of them instead of just the first one. Silly me! :) Thank you, Steve. For anyone else with a similar problem, run the JS function replace(/"/g,"\'") to your string to replace all the """s with "\'"s.
Jordan