PDA

View Full Version : ajax post containing ambersand & issue



jayapalchandran
02-02-2010, 10:20 AM
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???

CCH
02-02-2010, 09:33 PM
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

jayapalchandran
02-03-2010, 06:49 PM
Hi,
Beside using encodeURIComponent (which i got the answer from other forums) i can also use your method. thanks.