[wp-trac] [WordPress Trac] #14618: Proposal: Standardize WP Responses to JS Requests as JSON

WordPress Trac wp-trac at lists.automattic.com
Tue Oct 26 01:06:46 UTC 2010


#14618: Proposal: Standardize WP Responses to JS Requests as JSON
-------------------------+--------------------------------------------------
 Reporter:  filosofo     |       Owner:                
     Type:  enhancement  |      Status:  new           
 Priority:  normal       |   Milestone:  Future Release
Component:  JavaScript   |     Version:  3.0           
 Severity:  normal       |    Keywords:  needs-patch   
-------------------------+--------------------------------------------------

Comment(by filosofo):

 Replying to [comment:18 dd32]:
 > It should be worth noting here, That we do actually have a "standard"
 library for communication, the WP_Ajax_Response PHP Class and the WP Ajax
 Javascript library..

 In a very limited sense, it can handle integer responses.  It badly mixes
 presentation with data (note how you're expected to pass a DOM element for
 it to put response messages inside of).  It doesn't do much to help you
 with non-integer responses or syntactically invalid responses.  The other
 option is a DOM fragment with certain child elements and attributes.

 More importantly, it provides no standard for handling remote procedure
 calls: you can throw instructions at the server in any old way, and that's
 basically what happens throughout core and plugins.

 > The major problem with these libraries, is that people do not understand
 how to use them.. The 0/1 responses are valid and carry a known
 explanation, and the XML structures returned are also of a standard
 quantity.

 The major problem with these libraries is that they assume a narrow range
 of uses. XML's fine, but it does use more bandwidth for the same
 information than JSON.

 > If anything, This ticket should focus on integrating well with jQuery as
 well as being simple/powerful enough for 99% of developers to understand
 the code.

 jQuery is neither here nor there with respect to JSON, as it doesn't
 provide a way to encode JS objects into JSON.  If you have to rely on
 native methods or a JSON library anyways (my plugin's using Crockford's),
 there's no point in slapping on a 77k minified library just for 20 lines
 of XHR code. Note that my plugin's minified JS is 5k for everything: the
 JSON multi-browser compatibility, XHR, and JSON RPC-specific
 functionality.

 The standard of method, data, and response handlers makes it very easy for
 developers to understand, much more so than an anything-goes structure.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14618#comment:19>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list