how to get form action response without ajax in a good way?

allesgutevn

New Member
I know how to get an AJAX response:\[code\]$.post( '/action', { actiontodo: 'insert' } function (data) { alert(data); } );\[/code\]Int the action.php (server side):\[code\]<?php if ($_POST['actiontodo'] == 'insert') { doInsertAction(); echo "inserted"; } ?>\[/code\]Finally the output of this code is an alert BOX with the word: inserted.BUT, without ajax, I have two ways to solve this (in the server side):ONE: \[code\]<?php if ($_POST['actiontodo'] == 'insert') { doInsertAction(); header( "Location: " . $_SERVER['HTTP_REFERER'] . " &response=inserted" ); } ?>\[/code\]TWO:\[code\]<?phpsession_start();if ($_POST['actiontodo'] == 'insert') { doInsertAction(); $_SESSION['response'] = 'inserted';}header( "Location: " . $_SERVER['HTTP_REFERER'] );?>\[/code\]Returning to the page I get the answer from the SESSION or from GET and shows the alert.I like more the ONE solution, but each solution has a problem:ONE problem:The returning URL is : http://www.foo.com/myrefererurl&response=insertedIf you types this URL without using the form, you will see the alert BOX each time you will refresh the page. The question is: How to show the message only ONE time? (ONLY AFTER THE FORM ACTION)TWO problem:The SESSION now has the value inserted ($_SESSION['response']), when the page returns from the action obviously the solution maybe delete this value of the session like: unset( $_SESSION['response'], but SUPPOSE the UNSET do not reached for any reason (connection failure or navigation stopped by the user, etc), when you go to another form in other page the alert will showed because the $_SESSION['response'] still exists (in another form without submit it and has nothing to do with that response). Inclusively WITH GET &response=inserted in another URL the problem will exists too.I hope you understand this questions and bring a BEST WAY solution. Basically the question is how to control that responses......
 
Back
Top