Jump to content

[SOLVED] Passing array trough the URL... serialize problem!


Recommended Posts

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!

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....

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?

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.