1
$('#upload').on('click',function(){
$('#upload_form').ajaxForm({
    url:insert_url,
    type:'post',
    target:'#preview',
    beforeSubmit:function(e){
        console.log('before');
        $('.progress').show();
    },
    success:function(res, status, xhr, form){
        console.log('che');
        $('.progress').hide();
    },
    error:function(e){
        console.log('error');
    }
}).submit();

I have a post form, but I was wondering how to get Success function to work if my photos are uploaded. It seems the function is not called at all.

Please help me out if you know.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Chao LI
  • 99
  • 10

1 Answers1

0

Are you using jQuery form plugin? If so, make sure it's source added to the HTML and loaded without errors.

Your code seems incomplete, is it because you just have other stuff inside of $('#upload').on('click',function(){? If not, make sure that you close the function, here's what I mean (I also fixed the indentation):

$('#upload').on('click', function() {
    $('#upload_form').ajaxForm({
        url: insert_url,
        type: 'post',
        target: '#preview',
        beforeSubmit: function(e) {
            console.log('before');
            $('.progress').show();
        },
        success: function(res, status, xhr, form) {
            console.log('che');
            $('.progress').hide();
        },
        error: function(e) {
            console.log('error');
        }
    }).submit();
});

Also make sure that insert_url is defined before this code.

If it still doesn't work, does the console show "before", "che" or "error"?

Dmitry Gamolin
  • 934
  • 1
  • 12
  • 29