:) Finilly, I found a solution.
Here, I am posting a really simple example using ajax and cgi/perl (server site) to upload files.
No reload and no submit button.
I hope it helps for others as example.
AJAX simple_ajax_cgi_example.js<!--jquery should be included before any other js--> <script type="text/javascript" language="javascript" src="/simple_ajax +_cgi_example/jquery-1.2.6.js"></script> <script type="text/javascript" language="javascript" src="/simple_ajax +_cgi_example/simple_ajax_cgi_example.js"></script> <html> <body> <form action="/cgi-bin/simple_ajax_cgi_example.cgi" id="form1" name="f +orm1" encType="multipart/form-data" method="post" target="hidden_fra +me" > <input type="file" id="file" name="file" style="width:450"> <!--<INPUT type="submit" id="test" value="submit">--> <span id="msg"></span> <br> <iframe name='hidden_frame' id="hidden_frame" style='display:none'></i +frame> </form> </body> </html>
CGI/Perl simple_ajax_cgi_example.cgi$(document).ready(function () { $("#file").change(function() { $("#form1").submit(); }); }); function callback(msg) { $("#msg").html(msg); }
#!/usr/bin/perl use warnings; use strict; use CGI; my $form = new CGI; print $form->header; #Print HTML header. this is mandatory my $web_home = "$ENV{DOCUMENT_ROOT}/simple_ajax_cgi_example"; my $UPLOAD_FH = $form->upload("file"); my $newfilename = "new_file"; umask 0000; #This is needed to ensure permission in new file open my $NEWFILE_FH, "+>", "$web_home/tmp/$newfilename.txt" or die "Problems creating file '$newfilename': $!"; while ( <$UPLOAD_FH> ) { print $NEWFILE_FH "$_"; } close $NEWFILE_FH or die "I cannot close filehandle: $!"; ##this is the only way to send msg back to the client print "<script>parent.callback('upload file success')</script>"; exit;
In reply to Re: CGI upload from ajax
by flope004
in thread CGI upload from ajax
by flope004
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |