Currently I'm doing this in two steps:
1.post it to ask.php
2.after inserting it into database,use header("REFRESH: 0;URL=post.html")
to jump to the result page
But how to do it all in one step,say,like SO here?
Currently I'm doing this in two steps:
1.post it to ask.php
2.after inserting it into database,use header("REFRESH: 0;URL=post.html")
to jump to the result page
But how to do it all in one step,say,like SO here?
SO does it using Ajax. But for the easier win, why not just use header('Location: http://example.com/post.html')
instead of a refresh?
Instead of a that refresh header, after processing the POST request, tell the client to view the result with a Location redirection header
header("Location: http://www.example.com/post/$post_id");
It happens using ajax, I'm guessing.
-User types post, hits submit. -Post content is sent via ajax to the server where it tries to save it. -If it is saved: The post is added to the page using javascript and some pretty animations and all the various listeners are added to the clickable elements. -If not: Show some error.
I'm sure there's more to it than that, but that's probably the basic idea.
That kind of thing is done with Ajax. Using javascript to request small(er) amounts of data from the server, then updating the page, bypassing a full page request/refresh.
Here's a few libraries that may help get you started with Ajax and PHP: