1

I have to pass parameters using ajax.Updater to a php page. The post values to be passed contain characters like +,-,&,%,#.

I am encoding the parameters using encodeURIComponent before posting and decoding it using urldecode() in the php page.

I am unable to fetch the posted data in the php page. Please suggest how this can be handled.

Thank you

2
  • Can you show us, how you are sending the request? Commented Mar 18, 2011 at 12:34
  • 2
    Please show your code. encodeURIComponent is the right function. You probably don't have to do any decoding in PHP. This should be done automatically. Commented Mar 18, 2011 at 12:37

3 Answers 3

3

I used encodeURIComponent(value1). i.e I encoded each value and then posted. Prior, I was encoding the entire postBody.

Sign up to request clarification or add additional context in comments.

Comments

0

I highly recommend to use the "postBody" Option from Prototype: http://prototypejs.org/api/ajax/options

Using this option you don't have to encode the data. Just send the request as a POST request and fetch the data directly from the $_POST array in PHP.

1 Comment

I am using "postBody" Option from Prototype. The syntax is like postBody:"field1"=value1+"field2="+value2 But if I have a "+" or "&" in the value to be passed, the "+" and "&" is not fetched in the php page Eg. if field1="grade A+" then only "grade A" appears in php page
-1

An alternative to url encode is base64 encode then you can just retrieve the post data using $_POST and base64_decode() the results. base64 encode/decode is very common for example if you are already using JQuery: http://plugins.jquery.com/project/base64-encode-and-decode

1 Comment

I take it I was downvoted because base64 encoding can sometimes add spurious characters to the post data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.