php - Ajax url encoding issue -


what attempting send encrypted message , corresponding key (two way encryption) php page decrypted , have result returned in response.

here example of encrypted message trying send jquery.

var message = 'opnhk7de33xolzok/23a92xh9ni3slhgculnh6+iuzn4cghymym5yxomdyncdag8u+cabj4kifxzswsggmtxozoatjkahph/ewyuwmnfvintgmz4x02jvj6rc6wdsqzzd6mrl88zzxyeshd1/+9jrs9rnalctv//pc2frazmqhh5wxdn9kb6jitss/aagugfblmq+jxg5ty55skmri6ijg==';  var key = 'password';  $.post('decodemessage.php?message=' + encodeuricomponent(message) + '&key=' + key, function(data) {     // stuff returned data here }); 

the receiving php code follows

 <?php  $encrypted = rawurldecode($_post['message']);  $key = $_post['key'];   $decrypted = rtrim(mcrypt_decrypt(mcrypt_rijndael_256, md5($key), base64_decode($encrypted), mcrypt_mode_cbc, md5(md5($key))), "\0");   echo $decrypted   ?> 

the problem have is returning gibberish , not decoding message.

i have tested without ajax setting value of $encrypted encoded value being passed in ajax request , works fine.

i appreciate if offer me guidance why occurring.

many thanks.

send data object instead.

$.post('decodemessage.php', {message: message, key: key}, function(data) {     // wohoo }); 

you see, jquery takes care of stuff you, under layers of obscure code :-)


Comments