SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Passing '&' in url via get method. stragne problem!

  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    909
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Passing '&' in url via get method. stragne problem!

    Hai folks,

    my html form 'company description' field sends "Computer Repair & Maintenance" value to php via ajax get method.

    Code:
    $description = $_POST["description"];
    all i am getting is 'Computer Repair' part only. '& Maintenance' is missing.

    how to solve this issue?
    i just tried putting
    Code:
    $description =urlencode( $_POST["description"]);
    nop, not working..
    pls help

  2. #2
    Do. Or do not. There is no try silver trophy
    SitePoint Award Recipient ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,395
    Mentioned
    88 Post(s)
    Tagged
    2 Thread(s)
    you need to use encodeURIComponent in the AJAX script. When you're in the PHP you're too late, the damage is already done, because it will send your request like http://somedomain.com/?somekey=Computer Repair & Maintenance, so PHP will get array('somekey' => 'Computer Rapair ', ' Maintenance' => '');
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    909
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    you need to use encodeURIComponent in the AJAX script. When you're in the PHP you're too late, the damage is already done, because it will send your request like http://somedomain.com/?somekey=Computer Repair & Maintenance, so PHP will get array('somekey' => 'Computer Rapair ', ' Maintenance' => '');
    Thank you !! ill try what you suggessted.

  4. #4
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    909
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    you need to use encodeURIComponent in the AJAX script. When you're in the PHP you're too late, the damage is already done, because it will send your request like http://somedomain.com/?somekey=Computer Repair & Maintenance, so PHP will get array('somekey' => 'Computer Rapair ', ' Maintenance' => '');
    Works charm !!!
    Thank you Scallio

    Code:
    	var params = "name=" + encodeURIComponent(name) ;
    	var params = params + "&description=" + encodeURIComponent(description) ;
    	var params = params + "&address=" + encodeURIComponent(address) ;

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
  •