I'm using ajax as a form control which posts a value from a form to a php script to be checked etc before placing into a database. However the content can contain characters such as '&, $, £', how can I ask escape these using javascript so that errors don't occur when bad characters are input? Thanks
Well the problem is it's in a post manner so: variable1=content or post&variable2=second contest of post Works okay untill= something like: variable1=content or & post&variable2=second contest | of post
you can use escape('Your string') function in javascript.... so all your special characters will be converted to '%2%3F' like that to get back what you send you use unescape('received querystring')
So sending the post in javascript would be: var safeTest = escape(test); xmlhttp.open("POST","insertTest.php",true); xmlhttp.onreadystatechange = handleServerResponse; xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send("testPost=" + safeTest); Code (markup): Then in php to recover: $test = urldecode($_POST['testPost']); PHP: (The code is then checked to ensure it is safe before being inserted into a database)