PHP/Ajax - submitting a form inside a div

I'm looking for some pointers and/or some example code to overcome the following:

I have a php page (page1.php) that uses some ajax to present a div to a user when a button is clicked. The div contains some .php code (present as page2.php) to update some MySQL database data via a form contained within it.

Everything works as it should, however when i click to submit the form within page2.php my browser is redirect to page2.php and consequently the updated data.

I would like the browser to remain at page1.php, and only for the contents of the div to be updated with the new contents of page2.php.

How can i go about this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
Put the form in a page by itself and the page in an iframe

Alternatively if you use a library like prototype or extjs, ajax the form and tell the library to put the result in the div

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NoggywoggyAuthor Commented:
If i were to put the page in an iframe would i still be able to keep the ajax "animation" (if that's the right word?), that hides/shows the div when a link is pressed?
Michel PlungjanIT ExpertCommented:
No. So instead submit with ajax (assuming it is to the same website)
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

NoggywoggyAuthor Commented:
I just tried putting an iframe inside the div tags before you posted your reply, and it works exactly as it should.

I'm wondering whether i should give you the points now, given you said that's not the answer in your follow up response! :-)
Michel PlungjanIT ExpertCommented:
Sorry, I misread - I thought you meant an animation while the form submits.

Showing the div with animation is of course not influenced by what is in the div.
My apologies
NoggywoggyAuthor Commented:
Slight misunderstanding by both parties, but nevertheless the solution was reached promptly!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.