Problem with '&' (ampersand) in Send() function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AMT India
    New Member
    • Feb 2007
    • 64

    Problem with '&' (ampersand) in Send() function

    I am using POST method in Ajax. I have to send a number of items through POST.
    So I am creating a variable like this :

    [CODE=javascript]
    params += "name="+documen t.getElementByI d(name').value+ "&";
    params +="email="+docu ment.getElement ById('email').v alue+"&";
    params +="message="+do cument.getEleme ntById('message ').value+"&";
    ----------
    -----------
    http.open("POST ", url, true);
    ------------------
    ------------------
    http.send(param s);
    [/CODE]

    This code is working correclty. But some times name and message field's data contains '&' symbols. Then this cause problem with '&' in the parameter. The data is getting cutoff at this places. What is the solution for this problem?

    Thanks in advance..

    AMT India
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use encodeURICompon ent() around the values being passed.

    Comment

    • AMT India
      New Member
      • Feb 2007
      • 64

      #3
      Thank You

      Thanks a lot for your prompt reply....this code is working now!!!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You're welcome. Glad to be of assistance.

        Comment

        Working...