[wp-trac] [WordPress Trac] #30143: Using admin-ajax from the frontend
WordPress Trac
noreply at wordpress.org
Tue Oct 28 19:38:10 UTC 2014
#30143: Using admin-ajax from the frontend
-----------------------------------------------+---------------------------
Reporter: lukecarbis | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
Component: General | Review
Severity: normal | Version:
Focuses: javascript, template, performance | Keywords:
-----------------------------------------------+---------------------------
WP Ajax should not be used from the frontend because responses from
`admin-ajax.php` are not cached (including `nocache_headers()`). Also, it
has `admin` and `.php` in the URL.
Instead, we should add a query var, and then do the `template_include`
routine to select a template that returns JSON. This would also makes
sites more RESTful.
I've put together a bit of an idea of how this should work here:
https://gist.github.com/lukecarbis/6180629d7936d4b0a7eb
This routine is something that we could put in the docs, however, if parts
of this were implemented in core it would make things a lot simpler for
everyone.
My suggestion is to add `wp_ajax_action` to the default query vars, and
ajax callbacks inside the template loader (see the gist above for an
example).
(props @westonruter for some help putting this together)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30143>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list