I allow users to edit webpages using CKEditor and then save their modified HTML snippets to the server so that I can show them on subsequent page deliveries.
I'm using this code to send the HTML and a few IDs to the server:
var datatosend = JSON.stringify( { page: 1, block: 22, content: editor1.getData() } );
$.ajax({
url: "/ajax/fragment/",
type: "POST",
dataType: 'json',
data: "data=" + datatosend,
success: function (html) { },
error: function (xhr, status, msg) {
alert( status + " " + msg );
}
});
And on the server side I am using PHP and am doing this:
$json = stripslashes( $_POST[ "data" ] );
$values = json_decode( $json, true );
This works a lot of the time when non-HTML snippets are sent but does not work when something like this is sent in the content:
<img alt="" src="http://one.localbiz.net/uploads/1/Dido-3_2.JPG" style="width: 173px; height: 130px;" />
I'm really not sure what I am supposed to be doing in terms of encoding the data client-side and then decoding server-side? Also not sure if dataType: 'json' is the best thing to use here?