ltrem Posted June 23, 2009 Share Posted June 23, 2009 Hey guys, I'm doing some AJAX work on a website and here's my problems. I have a big array that look like this: $criterias['tomato'] = X $criterias['apple'] = X $criterias['juice'] = X I can't do the implode function because I'm loosing the 'tomato', 'apple'..... So I tried serialize function since unserialize returns me the array with the same structure... : $serialize = serialize($criterias); $to_pass_as_parameter = mysql_real_escape_string($serialize); print $to_pass_ass_parameter; // Return // a:6:{s:7:\"plan_id\";s:7:\"1001677\";s:10:\"searchType\";s:1:\"2\";s:3:\"cmd\";i:9;i:0;s:0:\"\";s:14:\"rss_content_id\";s:3:\"834\";i:1;s:0:\"\";} When I tried to retrieve the parameter in the URL, I only get a:6:{s:7:\\ Hope I'm clear.. your help would be extremely appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/ Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 I prefer JSON when I am working with AJAX. Try json encoding your array using json_encode(). Are you using an ajax library like jQuery? Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862138 Share on other sites More sharing options...
ltrem Posted June 23, 2009 Author Share Posted June 23, 2009 No jQuery... the website is built with the CMS Typo3... and for what I have to do I need to acces a PHP+MySQL with some Javascript function (onclick)... My Javascript retreive some value from different input in my pages and then call another .php script with those command (There is more but this is to show you what I use) : xmlhttp=GetXmlHttpObject(); xmlhttp.open("GET",url,true); xmlhttp.send(null); This is working great, my script is called and it can return the great value and display on the page I called the Javascript onclick... the problems is in my php script, The " that remains in the string from the serialize (JSON seems to return " too...) so the URL is messed up.... :S And I can't retreive all the information that the serialize returned.... Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862146 Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 Do you have magic quotes enabled? Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862155 Share on other sites More sharing options...
ltrem Posted June 23, 2009 Author Share Posted June 23, 2009 Yes Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862164 Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 That would be your problem I think. Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862167 Share on other sites More sharing options...
ltrem Posted June 23, 2009 Author Share Posted June 23, 2009 Could you please explain a bit more on why would that be my problems? Can't find any information really.. :S Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862172 Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 I'm actually a little confused as to what you are doing. You are making an ajax request to a php script and the php script returns a serialized array, right? And then you are making another ajax request to a php script with the serialized data as a GET parameter? Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862177 Share on other sites More sharing options...
ltrem Posted June 23, 2009 Author Share Posted June 23, 2009 Alright... here it is main_page.php load, create the html.. blablabla --> clicking on a button that call a javascript function --> That javascript call the script insert.php... URL = insert.php?id=1&title=allo&array=a:6:{s:7:\"plan_id\";s:7:\"1001677\";s:10:\"searchType\";s:1:\"2\";s:3:\"cmd\";i:9;i:0;s:0:\"\";s:14:\"rss_content_id\";s:3:\"834\";i:1;s:0:\"\";} Then, in my insert.php I want to retreive the array parameter which would be a:6:{s:7:\"plan_id\";s:7:\"1001677\";s:10:\"searchType\";s:1:\"2\";s:3:\"cmd\";i:9;i:0;s:0:\"\";s:14:\"rss_content_id\";s:3:\"834\";i:1;s:0:\"\";} But when I try $_GET['array'] in insert.php it only gives me this : a:6:{s:7:\\ :S Don't have nothing to do really with AJAX or Javascript... it's a problems of how to pass this in a URL since even with the slash, the GET method can'T retreive all the URL Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862186 Share on other sites More sharing options...
flyhoney Posted June 23, 2009 Share Posted June 23, 2009 You should true url encoding the serialized array using url_encode() Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862189 Share on other sites More sharing options...
ltrem Posted June 23, 2009 Author Share Posted June 23, 2009 You should true url encoding the serialized array using url_encode() urlencode() !!!! WOW ! GOTCHA! I think it work!!! Thank!! I'll try it out just to be sure and come back to tag the thread SOLVED ! Thanks alot!!!! Your the man! hehe Quote Link to comment https://forums.phpfreaks.com/topic/163404-solved-passing-array-trough-the-url-serialize-problem/#findComment-862199 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.