Sunday, December 26, 2010

Uploading a file with JQuery

You can easily submit data in an html form via jQuery's $.post. But you need to do a little more to upload a file. I suggest the jQuery Form Plugin.

Here is the HTML form:
<html>
<head>
<title>Carter Tomorrow Fund Donations</title>


 
</head>
<body>
</body> </html>

This is the Javascript file myFrom.js:



And here the cgi script "test.cgi" in Ruby



Make sure that your cgi script has the right permission, 755. Of course you would first manipulate the data instead of just mirroring it.

8 comments:

  1. It's not working...
    And why form is after html ?

    ReplyDelete
  2. hahaha let me try first.... wish it works.
    (^^'a...

    ReplyDelete
  3. works...!! it workss...!!!!

    I used it in a jsp environment... and it works...!!

    (god bless u, author). :D

    ReplyDelete
  4. Thanks for this post!!! I had to change some things up to refresh a DIV with an MVC Partial View, but this post definitely pointed me in the right direction! Thanks again!

    ReplyDelete
  5. I get this error: $("form").ajaxForm is not a function

    please help!!

    ReplyDelete
  6. How can we use this in a JSP environment? I need to know this urgently? I mean how can I submit this to a servlet and process the upload? Can someone please help?

    ReplyDelete
  7. upsss..sorry, i dont read carefully..there's an explanation about file "myForm.js"

    Let me try this code first :)

    ReplyDelete