Answer the question
In order to leave comments, you need to log in
Laravel how to send code 102 in controller and then 200?
What should I write in the controller to repeat the simple example below?
<?php
header('HTTP/1.1 102 Processing'); // let client know it might take a while
sleep(2); // do stuff that takes a while
header('HTTP/1.1 200 OK'); // counterintuitive, but works
public function destroy($id)
{
try {
$auto_mark = Mark::findOrFail($id);
} catch (\Exception $e) {
return $this->failedRequest('NOT_FOUND');
}
try {
$auto_mark->delete();
} catch (\Exception $e) {
return $this->failedRequest('DELETE_FAIL');
}
return response()->json(['status' => 'success'], 200);
}
Answer the question
In order to leave comments, you need to log in
Are you sure that it is in this context should be used?
It seems to me that the sequence here is something like this:
1. A request for a lengthy operation is sent from SPA using, for example, ajax.
2. At certain intervals, a request is sent via ajax about the status of the task. The server responds with 102 if the task is still running, and in the body, for example, the percentage of completion.
3. At the next status request, the server responds with 200, indicating the operation performed. SPA changes the interface accordingly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question