SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member bag's Avatar
    Join Date
    Jun 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX Post information includeing &

    Im guessing its quite simple, but ive been googling for a while and still not found what im looking for.

    Basically my news system POSTS an xmlhttp request containing the news, this news often includes urls which have the symbol "&" in them.

    The problem is, when ever an & appears in the send, the news gets cut off
    The reason is quite obvious, since its simply considering it a new post header.
    Code:
    xmlhttp.send("title=" + ctitle + "&comment=" + ccom);
    Im guessing i need to somehow encode it, but i haven't got a clue how. Can anyone get me a solution?

    Thanks in advance

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,260
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    ampersand

    Using only & in URLs causes problems because entities begin with them. You could try
    HTML Code:
    xmlhttp.send("title=" + ctitle + "&comment=" + ccom);
    or maybe
    HTML Code:
    var send_str = "title=" + ctitle + "&comment=" + ccom;
    var encoded_str = escape(send_str);
    xmlhttp.send(encoded_str);

  3. #3
    SitePoint Member bag's Avatar
    Join Date
    Jun 2006
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah thanks the second suggestions worked great, although i had to change slightly so as not to filter the & i actually did want
    Code:
    xmlhttp.send("title=" + escape(title) + "&cat=" + escape(cat) + "&update=" + escape(update) + "&news=" + escape(news) + "");


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
  •