Forums / Cotonti / Extensions / AJAX parts in plugs

GHengeveld
#24279 2010-04-23 05:18
I noticed that it's not possible to do a POST request to plug.php?r=abc because that will send the $r along with the POST vars, not GET.

I've fixed this in changeset 1213.
With these changes you can make POST request using the ajax hook.

Note that for POST, sending the sourcekey along with the request is required. You can easily put the key in your JS with the {PHP.sys.xk} tag (in tpl files), so you'd get something like this:

$.post('plug.php?r=abc&x={PHP.sys.xk}', 
{ "varname": "value" }, 
function(){ 
// do whatever 
});

Added 5 minutes later:

Also I really recommend testing your jQuery POST requests with RESTTest. It's easy to check the server's response to your POST request that way. (don't forget the sourcekey)
This post was edited by Koradhil (2010-04-23 05:29, 14 years ago)