Jump to content

AJAX doesn't like ampersands.


Arbu
 Share

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");
			      xmlhttp.send(sendstring);
	
		}

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?

Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...