开发者

How to encode POST parameter in javascript and decode it in php?

开发者 https://www.devze.com 2023-02-17 11:49 出处:网络
I have to pass parameters using ajax.Updater to a php page. The post values to be passed cont开发者_运维问答ain characters like +,-,&,%,#.

I have to pass parameters using ajax.Updater to a php page. The post values to be passed cont开发者_运维问答ain 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


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消