0

I have the following problem: I have two pages. In the first page is a button. When the button is clicked, an ajax request is made to a page that saves data to the session. Then, it redirects me to the second page in which I display this saved data. The problem is that when I go to the second page the data is not displayed, but when I refresh the page the data is displayed. How can I redirect to the second page with the session data stored?

Example:

Before Refresh:

Before Refresh

After:

After

Does anyone have any ideas?

5
  • 3
    If giving example images, post them to the question. Do not link to external objects since they may not be there in the future. Commented Mar 1, 2013 at 13:59
  • You could probably just add a small delay after your Ajax request returns successfully and before you redirect the user. Actual code would help. Commented Mar 1, 2013 at 14:01
  • a setTimeOut for example? Commented Mar 1, 2013 at 14:02
  • you should edit your question to A. post the external objects and B. post your current Ajax code. Commented Mar 1, 2013 at 14:06
  • i fixed it on complete callback i redirected to the other page Commented Mar 1, 2013 at 14:11

2 Answers 2

3

You should wait for the response of the AJAX request before you forward to the next page.

Preferable use the callback method to redirect to the next page.

If you post some code may be it will be easier to point out.

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

3 Comments

How much time must I wait?
Thats the point with callback. You dont have to wait. Once server sends a response it means(I am assuming) the data was set to session.
now i understand i will make oncomplete callback to redirect me to the page thank you
0

Try this, hope it'll work if you are using jQuery then fine, use e.preventDefault(); and redirect your next page after getting the ajax response.

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.