Jump to content

AJAX doesn't like ampersands.

Recommended Posts

I'm sending some information to the server with AJAX:

function saveFileToAccount(filename){
			/** [Storing JSON representations of the canvas] */
                var data = formattedJSON();
                /** [Store preview of transaction diagram] */
                var image = canvas.toSVG();
				var xmlhttp = new XMLHttpRequest();
			      var sendstring = "filename=" + filename + "&json=" + data + "&image=" + image;
			      xmlhttp.open("POST", "includes/process_save.php", true);
			      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

This goes into an SQL database and I get it back with php when a new page is opened. But the data comes back truncated at the first ampersand that it contains. How do I fix this? I suppose I could convert all the ampersands into a little used character before saving the data and then convert them back when it comes back, but that doesn't seem very satisfactory. Is there a proper way to sort this out?


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...