In a MySQL database i have the following entry: “Fruits & Vegetables”
I retrieve this to display on a webpage using PHP, convert to JSON, pass to client, process using JavaScript. the PHP code that is passed to the client is
$z = rawurlencode(json_encode($reqVar));
echo $z;
where $reqVar is the array of results queried from database, including one that is “Fruits & Vegetables”.
When it’s passed to client using AJAX, the JavaScript to process the string (decode it and then convert from JSON string to object using Prototype framework) is.
var response = decodeURIComponent(transport.responseText)
var respObj = response.evalJSON(true);
I can then display it in page. but when i pass it back to the PHP script using AJAX using the exact same process in reverse, at some point & is converted to & and if i re-enter it into the database it looks like “Fruits & Vegetables”. How can i prevent this conversion??? does the order in which i convert to and from JSON and encode/decode need to be changed?
Thanks, G