yosafat yosafat - 1 month ago 9
jQuery Question

Jquery is it possible to refresh page if download start?

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?

Answer

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

Comments