HTML and CSS Reference
In-Depth Information
}
else {
header ( 'Status: 400' );
}
}
function sendStandardResponse ( $added ) {
if ( $added ) {
header ( 'Location: index.php' );
}
else {
header ( 'Location: index.php?error=Your comment was not posted
due to errors in your form submission' );
}
}
?>
If you run the app now in two different browser windows you'll see that as soon as you submit
a comment in one window that comment will instantly ("magically") appear in the second
window. We now have a real-time commenting system!
But… , we're not done quite yet. You'll also see that the comment is shown twice in the window
of the user who submitted it. This is because the comment has been added by the AJAX
callback, and by the Pusher event. Because this is a very common scenario, especially if
you've built an application in a progressively enhanced way as we have, the Pusher server
libraries expose a way of excluding a connection/user from receiving the event via Pusher.
27
In order to do this you need to send a unique connection identifier called a socket_id from the
client to the server. This identifier can then be used to define who will be excluded.
function handleSubmit () {
var form = $ ( this );
var data = {
"comment_author" : form . find ( '#comment_author' ). val (),
"email" : form . find ( '#email' ). val (),
"comment" : form . find ( '#comment' ). val (),
"comment_post_ID" : form . find ( '#comment_post_ID' ). val ()
 
Search WWH ::




Custom Search