0

I am trying to to solve a problem where I need to pass large arrays of data to another page, this is my scenario:

The user input his/her gmail login information inside a form, I then send this information to an ajax page where i authenticate and fetch all the contacts, if the login is invalid they can try again but if it authenticated I need to send them to the next page where I parse all the emails and check if they match any users on the site.

Method 1 (didn't work):

Store all the data inside a session, this only work if the array is small as there is a size limit for the sessions.

Method 2 (didn't work):

Add an hidden input with javascript and then submit the form (also with javascript). As it turns out you can't submit the form and return true (change page) unless the user triggers the event.

So how should I go on, should I just skip the ajax authentication and send them back to the previous page if it didn't work or is there some workaround to my problem?

2
  • "As it turns out you can't submit a form without a real user click" I do this all the time - care to elaborate about the specifics of your form that make it unable to be submitted with javascript? Commented Nov 11, 2009 at 16:43
  • I thought it was possible but I couldn't get it to work so I searched for a solution and found this: stackoverflow.com/questions/645555/… Commented Nov 11, 2009 at 18:55

4 Answers 4

3

Why don't you store the data in a database, MySQL, or SQLite if MySQL is not available to you. In there, you would store a serialized version of your array linked to the users session id.

The MySQL table I'm thinking of:

id | session_id | data

http://php.net/manual/en/function.serialize.php on how to serialize your array.

Sign up to request clarification or add additional context in comments.

2 Comments

Thats a good idea. I think I will go with this solution, its faster then fetching the data once again from the webservice.
Be careful with this approach. It works when you have a single database, but if you ever need to scale past that it's not going to work reliably. The lage between a master DB replicating out to it's slaves is often longer than the lag between page loads.
0

If you are able to fetch the data again on the next page, you could do that instead of passing it between pages.

1 Comment

the call usually takes 3-6 seconds so I think x3ro's solution will be the optimal way of doing it.
0

Since you are using jQuery you can submit the data directly or as a hidden element on the form without a user click. Assuming the second submission is via AJAX you can:

 $("#mydiv").load("secondpage.php", {email1: 'blah'}, function(){
   alert("Submitted everything nicely");
 });

5 Comments

that will disable the back button, is it possible to keep the back button and do it this way?
To do it without AJAX you can use the '$("form").submit()' which does a full post. So you can add your hidden fields and submit the form from code.
That doesn't work, I cant trigger the submit function without a user click. I got it confirmed here:stackoverflow.com/questions/645555/…
What do you want to do in the onsubmit? As I understand it you can submit a form without user click, only it will not fire the onsubmit event...that should be easy to work around.
You can submit the form but all thats happens is that you run the submit function but It wont take you anywhere. The code just stop running after return true.
0

Depending on your webserver, but session variables do not typically have a size restriction. Apache+PHP you could handle extremely large sizes, instead you should care about http://ca.php.net/manual/en/ini.core.php#ini.memory-limit. In addition, PHP.ini carries session.size variable that you could adjust. I am not sure how it did not work for you; you used $_SESSION, right?

Finally, to make a better persisting yet fast (faster than Database) volatile storage I would recommend using Danga's memcached. It is very stable, widely used and has wrappers for every possible language flavor.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.