Make AJAX requests on activity page POST not GET

See parent commit for the reason we’re doing this.

Currently our AJAX requests only work as `GET` requests. So this commit
does a bit of work to make them work as `POST` requests. This is
optional behaviour, and will only happen when the element in the page
that should be updated with AJAX has the `data-form` attribute set. It
will take the form that has the corresponding `id`, serialise it, and
use that data as the body of the post request. If not form is specified
it will not do the serialisation, and submit as a `GET` request as
before.
This commit is contained in:
Chris Hill-Scott
2017-06-13 11:20:41 +01:00
parent e65dcbe199
commit 681cea1d34
5 changed files with 16 additions and 16 deletions

View File

@@ -19,10 +19,14 @@
var clearQueue = queue => (queue.length = 0);
var poll = function(renderer, resource, queue, interval) {
var poll = function(renderer, resource, queue, interval, form) {
if (queue.push(renderer) === 1) $.ajax(
resource
resource,
{
'method': form ? 'post' : 'get',
'data': form ? $('#' + form).serialize() : {}
}
).done(
response => flushQueue(queue, response)
).fail(
@@ -41,7 +45,8 @@
getRenderer($(component)),
$(component).data('resource'),
getQueue($(component).data('resource')),
($(component).data('interval-seconds') || 1.5) * 1000
($(component).data('interval-seconds') || 1.5) * 1000,
$(component).data('form')
);
};