SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [ajax] Problem with pass text content &

    I use this code to passing from ajax to a page php 2 variable:titolo and messaggio.

    sendReqForum.open('POST', '{$path}forum_get.php?id=$id&forum_sezione=$forum_sezione&discussione='+discussione, true);
    sendReqForum.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    sendReqForum.onreadystatechange = handleSendForum;
    var param = 'messaggio=' + document.getElementById('messaggio').value+'&titolo='+document.getElementById('titolo').value;
    sendReqForum.send(param);

    it works correctly if the document.getElementById('messaggio').value or document.getElementById('titolo').value don't contain '&'.
    for example if document.getElementById('titolo') is "hello & goodbye"
    The text that the page php receive is only "hello"
    How i can do?
    Thanks

  2. #2
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you need to use encodeURIComponent().

    so it should be...

    var param = 'messaggio=' + encodeURIComponent(document.getElementById('messaggio').value)+'&titolo='+encodeURIComponent(document.getElementById( 'titolo').value);
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site


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
  •