SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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. #2
    SitePoint Zealot Gar onn's Avatar
    Join Date
    Feb 2011
    Location
    Belgium
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    didnt 'decodeURIComponent' convert %20 into " " (space) ?


Bookmarks

Posting Permissions

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