Results 1 to 3 of 3

Thread: ajax post containing ambersand & issue

  1. #1
    Join Date
    Jan 2007
    Location
    Chennai, Tamil Nadu, India
    Posts
    31
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default ajax post containing ambersand & issue

    Hi, I am back again with clarification in ajax post.
    I am having a WYSIWYG (TinyMCE) editor for a description field.
    I am posting it using AJAX.

    Assume that the data is "lorum ispum & <p>sample text<p>"
    so it will be like

    var udescription = "lorum ispum&sampletextandothertext";
    xmlhttp.open("POST","ajax.php?description="+udescription",true);

    Obviously this will get posted as usual form the client side.
    But the server parses it as

    Array (

    [udescription] = [lorum ispum],
    [sampletextandotherext] = ''

    )

    that is, any letters after an ambersand is consider as a key and it searches for the '=' sign to take the value next to it...

    so if i send "ajax.php?name=joe&number=989898&description=sample&one&two"

    it will be like

    name = joe
    number = 989898
    description = sample
    one =
    two =

    So what i think is doing a base64encode here and doing a base64decode in the server side.

    I have base64encode function for javascript.

    Will this solution holds good or am i m i s s i n g something.
    Do people have an alternate or a suggestion. Please provide any kind of info so that we forum users will update it.

    How does a browser send data to the server. hope it sets the mime type to base64 and the server would check it and decode it.
    The post data would be 7 bit, 8bit and base64 and then multipart data seperated by boundaries.

    so we have to set a different content type or use additional methods of XMLHTTPRequest???

  2. #2
    Join Date
    Oct 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    just replace the & symbol with the URL encoded version %26 when generating the query string, the resulting page will see the & symbol, instead of thinking it's starting a new key.

    for example:
    instead of ajax.php?name=joe&number=989898&description=sample&one&two
    use ajax.php?name=joe&number=989898&description=sample%26one%26two

  3. #3
    Join Date
    Jan 2007
    Location
    Chennai, Tamil Nadu, India
    Posts
    31
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default nice

    Hi,
    Beside using encodeURIComponent (which i got the answer from other forums) i can also use your method. thanks.

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
  •