0

i have this form which is appended onclick of a div

$('#div').click(function(){
   $('#div').load('form.php');
});

here is the form appended

    <form id="addpic" name="addpic" method="post" enctype="multipart/form-data" action="docupload.php">
      <input type="file" name="mfoni" id="upper1" style="height:10px; width:100px; cursor:hand;" />
      <input type="hidden" name="user" value="<?php echo $id; ?>" id="user" />
   </form> 

now i want to submit the form without refreshing the page or redirecting with the code below

$("input#upper1").live('change', function(){
       alert("gone");
       // works up to this point
       $("form#addpic").ajaxForm({
         target: '#loading'
      }).submit();
    })

this works up to the alert('gone') point and it stops please healp me out

4
  • 1
    .live function is deprecated Commented Oct 26, 2013 at 7:50
  • 2
    As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live(). Commented Oct 26, 2013 at 7:50
  • is the syntax for delegate() the same as live() Commented Oct 26, 2013 at 7:52
  • @user2922439: Which version of jQuery are you using? Commented Oct 26, 2013 at 8:00

1 Answer 1

1

It looks like you are missing below external JS file reference

http://malsup.github.com/jquery.form.js

The other thing is you need to use .on() rather than using .live(). Since live() method has been deprecated in jQuery 1.7.

You no need to use ajaxForm() and .submit(). Just use ajaxSubmit().

JS Code:

$("input#upper1").on('change', function(){
    alert("gone");
    $("form#addpic").ajaxSubmit({
        type: "post",
        success: function() {
            alert("Processed");
        },
        complete: function() {
            alert("File upload is completed");
        }
    });
});

Refer LIVE DEMO

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.