tenants
Well-known member
okay, so all of the ajax tutorials are about forms, and the classes you can use that make your life easier...
It works pretty well, but what if you don't want to submit a form
Lets say, a person visits a page, I then want to do some background js which calls an action (the background jobs shouldn't stop the page from loading and the user from using that page, so why make them wait!... a background job via ajax works for this)
I also want the response of that action
With forms, getting the sesponse is easy, but if you are not using xf forms, what should you do
here's an example of what I mean:
This kind of works, but I can't figure out how to get the response back
The BackgroundJob runs, for now I just send responseError('whatEver') for my response to actionSomeBackgroundJob
I would like to send something like:
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
dont redirect me!,
'Updated BackgroundJob',
array('sendThisBack' => $data['xyz'],)
);
but this wont work, since it redirects, so what should I use to get $data['xyz'] back ?
I could do this by creating a hidden form and then submitting that using form.submit... but it feels wrong? Is it, should I use a hidden form?
It works pretty well, but what if you don't want to submit a form
Lets say, a person visits a page, I then want to do some background js which calls an action (the background jobs shouldn't stop the page from loading and the user from using that page, so why make them wait!... a background job via ajax works for this)
I also want the response of that action
With forms, getting the sesponse is easy, but if you are not using xf forms, what should you do
here's an example of what I mean:
PHP:
<script>
$(document).ready(function() {
var dataString = 'x={$x}' + '&_xfToken={$visitor.csrf_token_page}';
$.ajax({
type: "POST",
url: "{xen:link something/someBackgroundJob, $data}",
data: dataString,
success: function(){}
});
$('a#z').text('new text');
});
</script>
This kind of works, but I can't figure out how to get the response back
The BackgroundJob runs, for now I just send responseError('whatEver') for my response to actionSomeBackgroundJob
I would like to send something like:
return $this->responseRedirect(
XenForo_ControllerResponse_Redirect::SUCCESS,
dont redirect me!,
'Updated BackgroundJob',
array('sendThisBack' => $data['xyz'],)
);
but this wont work, since it redirects, so what should I use to get $data['xyz'] back ?
I could do this by creating a hidden form and then submitting that using form.submit... but it feels wrong? Is it, should I use a hidden form?