SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy help with '&' and vars

    hello ,

    I'm using this function to pass variables ( in comment system ) to the php page

    Code:
    function sendRequestPost (SubjectText,thread,forum,user_id,user_name) {
    	http.open('post', 'http://localhost/storm/quick_reply.php');
    	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    	http.onreadystatechange = handleResponse;
    	http.send('SubjectText='+SubjectText+'&thread='+thread+'&forum='+forum+'&user_id='+user_id+'&user_name='+user_name);
    }
    but i have problem when the SubjectText value content this sing '&'

    the php file treates - only - with the first part of the text , before the '&'


    Thanks, Respect

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use encodeURI().

    Code:
    http.send('SubjectText='+encodeURI(SubjectText)+'&thread='+thread+'&forum='+forum+'&user_id='+user_id+'&user_name='+user_name);
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    encodeURI does not encode & and also +.

    Use encodeURIComponent instead.

    Code:
    >>> encodeURI('&+');
    "&+"
    >>> encodeURIComponent('&+');
    "%26%2B"

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're right. Thanks for catching that, the DtTvB.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  5. #5
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot the DtTvB, it worked


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
  •