:) 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.

HTML
<!--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>
AJAX simple_ajax_cgi_example.js
$(document).ready(function () { $("#file").change(function() { $("#form1").submit(); }); }); function callback(msg) { $("#msg").html(msg); }
CGI/Perl simple_ajax_cgi_example.cgi
#!/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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.