tags:

views:

78

answers:

4

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?

+3  A: 

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?

chaos
Is there any difference ?
Shore
Yeah, they're pretty different. Redirecting the user using `Location` is loading up a new Web page, whereas using Ajax you'd be integrating the new display elements into the page they're currently on.
chaos
A: 

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");
Paul Dixon
A: 

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.

inkedmn
A: 

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:

XAJAX

Zend_Json_Server (more complex)

PHP Ajax Example at W3Schools

Tim Lytle