Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get rid of the intermediate layer completely

* Instead of the success/message/data structure just send what before
was the data.
* On the client side assume the reponse is the data, don't look for it
one level deeper.
* This allowed us to simplify the success/error callbacks.
* When addding an error don't look for the message in the reponse, but
just assume it's an HTTP error response.
  • Loading branch information...
commit 20c5b02548f7d1564b346f69e0107b60902a335d 1 parent e977561
@nb nb authored
Showing with 9 additions and 23 deletions.
  1. +6 −17 js/liveblog.js
  2. +3 −6 liveblog.php
View
23 js/liveblog.js
@@ -59,10 +59,10 @@ var liveblog = {};
liveblog.hide_spinner();
- if (response.data.entries.length)
- liveblog.latest_entry_timestamp = response.data.latest_timestamp;
+ if (response.entries.length)
+ liveblog.latest_entry_timestamp = response.latest_timestamp;
- liveblog.display_entries( response.data.entries );
+ liveblog.display_entries( response.entries );
liveblog.reset_timer();
liveblog.undelay_timer();
@@ -199,15 +199,8 @@ var liveblog = {};
data: data,
type: method,
dataType: 'json',
- success: function( response ) {
- if ( 1 == response.status )
- success_callback( response );
- else
- error_callback( response );
- },
- error: function( response ) {
- error_callback( response );
- }
+ success: success_callback,
+ error: error_callback
} );
}
liveblog.success_callback = function() {}
@@ -216,11 +209,7 @@ var liveblog = {};
liveblog.add_error = function( response ) {
// TODO: show errors in a box near the nag
// TODO: throtle errors
- console.log(response);
- if ( response.message )
- alert( 'Error: ' + response.message );
- else if ( response.status && response.statusText )
- alert( 'Error ' + response.status + ': ' + response.statusText );
+ alert( 'Error ' + response.status + ': ' + response.statusText );
}
liveblog.show_spinner = function() {
View
9 liveblog.php
@@ -320,17 +320,14 @@ function ajax_check_nonce( $action = 'liveblog_nonce' ) {
}
function json_return( $data ) {
- $return = json_encode( array(
- 'status' => 1,
- 'message' => '',
- 'data' => $data,
- ) );
+ $json_data = json_encode( $data );
header( 'Content-Type: application/json' );
if ( self::$do_not_cache_response ) {
nocache_headers();
}
- echo $return;
+
+ echo $json_data;
exit;
}
Please sign in to comment.
Something went wrong with that request. Please try again.