Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do i keep "&" from being converted to "&" ?

    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

    Code:
    $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.

    Code:
    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

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,753
    Thanks
    41
    Thanked 191 Times in 190 Posts
    i think this may be a SQL question more than an ajax... but none-the-less... (not sure of direct answer as I have no xp w/ php) but the term you are looking for is passing a literal value... so you want the & to display literally... see a similar thread I posted as I was having an issue with needing to display literally \D in my C# code... each language has it's own "method" for incoperating this... make sure you keep this in mind when assembling your strings

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •