fishbaitfood Posted September 10, 2011 Share Posted September 10, 2011 Hey all, I have this form I'd like to submit without a page refresh. Someone said it was as simple as using the Ajax .request() function.. Seems unlikely to me? So basically, I have this form with data, which will be inserted into a database after submit, and instantly goes back to the form page using header('Location: index.php'). Besides the refresh, this works perfectly. Is it possible, to post my form without a refresh, but still submitting data to the process page where the data is inserted into tables and brings me back with header? So Ajax or jQuery doesn't need to fetch the output from the process page, but just post it. Sure this is possible, right? I've tried to find examples on my situation, but I haven't found one. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/246862-submit-form-without-page-refresh/ Share on other sites More sharing options...
fishbaitfood Posted September 12, 2011 Author Share Posted September 12, 2011 Anybody can help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/246862-submit-form-without-page-refresh/#findComment-1268286 Share on other sites More sharing options...
ploppy Posted September 14, 2011 Share Posted September 14, 2011 You would need to use a library like jquery. You could also use there serialize function which would process all form elements then submit to php using ajax. Quote Link to comment https://forums.phpfreaks.com/topic/246862-submit-form-without-page-refresh/#findComment-1269153 Share on other sites More sharing options...
fishbaitfood Posted September 14, 2011 Author Share Posted September 14, 2011 Thanks for your reply! But in all scripts I've seen so far, to send a form with ajax, it needs an "output" back, right? In my case, I just want to send the form, only send. My process page has a header('Location: index.php'), to get back. But I guess that won't work, right? Quote Link to comment https://forums.phpfreaks.com/topic/246862-submit-form-without-page-refresh/#findComment-1269174 Share on other sites More sharing options...
AyKay47 Posted September 14, 2011 Share Posted September 14, 2011 what do you mean "output" back? jquery can send the data to the specified page without receiving "output" back.. Quote Link to comment https://forums.phpfreaks.com/topic/246862-submit-form-without-page-refresh/#findComment-1269175 Share on other sites More sharing options...
fishbaitfood Posted September 14, 2011 Author Share Posted September 14, 2011 So this line should do it? $.post('process.php', $("#myform").serialize()); But the header('Location: index.php') when the process is complete, will cause a refresh I guess, right? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/246862-submit-form-without-page-refresh/#findComment-1269187 Share on other sites More sharing options...
AyKay47 Posted September 14, 2011 Share Posted September 14, 2011 should, and its hard to tell without seeing the entire relevant code.. but if you have a header() after this code then yes it will redirect you to that url.. Quote Link to comment https://forums.phpfreaks.com/topic/246862-submit-form-without-page-refresh/#findComment-1269208 Share on other sites More sharing options...
fishbaitfood Posted September 14, 2011 Author Share Posted September 14, 2011 Dang, it's really that simple huh?! It worked. I just needed to remove that header('Location: index.php') in my process page. Weird that I haven't tested this earlier... :-\ Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/246862-submit-form-without-page-refresh/#findComment-1269219 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.