Zaxnyd Posted April 25, 2007 Share Posted April 25, 2007 I'm looking for a failsafe way to send a serialized php object through AJAX. I posted <a href="http://www.phpfreaks.com/forums/index.php/topic,137636.0.html" target="_blank">my problem in the php section</a>, but haven't had a whole lot of luck there. Maybe you ajax pros have figured a way to do this. This is my failed attempt: (it works up until the data is passed via url, when it becomes corrupted) $serialize = serialize($myObject); $base64_encode = base64_encode($serialize); $urlencode = urlencode($base64_encode); //pass via Ajax / GET $urldecode = urldecode($urlencode ); $base64_decode = base64_decode($urldecode); $myObject= unserialize($base64_decode); Quote Link to comment Share on other sites More sharing options...
Zaxnyd Posted April 25, 2007 Author Share Posted April 25, 2007 Solved it. It was the pesky plus sign that was doing it. So I just did an eregi_replace with a placeholder and it works wonderfully. Here's the class I made. Some of you might appreciate it: class url_serializable { function loadFromSerial($sSerial) { $urldecode = urldecode($sSerial); $urldecode = eregi_replace("--PLUS--", "\+", $urldecode); $base64_decode = base64_decode($urldecode); $unserialize = unserialize($base64_decode); return $this->loadFromObject($unserialize); } function sSerialized() { $sSerialized = $this; $sSerialized = serialize($sSerialized); $sSerialized = base64_encode($sSerialized); $sSerialized = eregi_replace("\+", "--PLUS--", $sSerialized); $sSerialized = urlencode($sSerialized); return $sSerialized; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.