Reputation: 253
i have an application which the user choose the checkbox
,
press button download
and download the data based on checked box,
the problem is if i am not checking any checkbox
, it will show error
message in div
alert.
and when i check and click download, download run well, but the error message is still in the page.
how to detect if download start, automatically page refresh, or how to solve it more easily?
my download code :
public function downloadFile($name)
{
$storagePath = "/opt/tmp/";
// check filename for allowed chars (do not allow ../ to avoid security issue: downloading arbitrary files)
if (!is_file("$storagePath/$name")) {
throw new \yii\web\NotFoundHttpException('The file does not exists.');
}
return Yii::$app->response->sendFile("$storagePath/$name", $name);
}
how i can make detect download start and refresh it using jquery?
Upvotes: 0
Views: 399
Reputation: 2512
You can detect download start when client click download link.
Before send request!
Something like this:
$('#download-link').on('click', function() {
setTimeout(function() {
document.location.reload();
}, 500);
return true;
});
Upvotes: 1
Reputation: 496
You need to Hide the Error message as soon as you click on Checkbox. something Like that $("#id").hide();
Here id is the Id of the error message div
Upvotes: 3