I have an html form used to upload a file to a server. For brevity, I have shown only the main points
<form id='uploadform' method='post' enctype='multipart/form-data' action='index.php/upload'> <input name='myFile' id='myFile' type='file'/> </form> <input type='button' id='upload' value='Upload'/> <div id='response'></div>
I use jQuery.submit () to submit the form:
$('#uploadform').submit();
Business logic is Slim PHP: $ app-> post ('/ upload', 'uploadFile'); ....
function uploadFile(){ try{ // if success uploading $app->redirect('/main-page'); }catch(Exception $e){ // if error echo $e->getMessage(); } }
Problem: If the download fails for some reason, an exception is thrown, the user goes to the PHP error page. If the download is completed without exception, the application is redirected to the main page.
Required: if the download is completed successfully, the application should be redirected to the main page, as it is now ... but if any exception occurs, instead of going to the PHP error page, the application should remain on the download page and with id = 'response' should display an exception.
Is it possible to do something like this using jQuery submit ():
$('#uploadform').submit(function(response){ $('response').html(response); });
????
I know that plugins for downloading jQuery files will make life easier ... but this is not an option for me ...
Thanks for any pointers!
Is it possible
source share