SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX POST Ampersand (&) Problem

    Hello,
    I'm having a huge problem posting form data using AJAX. The & symbol appears in multiple posts and is messing up all of the variables. The only thing i can think of doing is replacing all of them with a temporary value and then changing them back once the data is send to the php page. Is there a better/more efficient way of doing this?

    Thanks in advance!

  2. #2
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,564
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Mind showing us the code? We aren't mind readers (I know this dude in real life, he's a dweeb ).
    Twitter-@Ryan_Reese09
    http://www.ryanreese.us -Always looking for web design/development work

  3. #3
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll give you an example.

    Say I'm using post to send some data

    Code:
    var params = "title=Sample Title&name=Sample Name";
    Well, if the title has an '&' in it, such as "HTML & JS", the code would look like this:

    Code:
    var params = "title=HTML & JS&Title&name=Sample Name";
    Thus killing my code because it thinks 'JS' is a variable.

  4. #4
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem solved!

    Using the encodeURI() and escape() functions will remove all traces of special characters, and then I can decode using JS or PHP.


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
  •