2016-10-01 76 views
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(); 

我有一个帖子表单,但我想知道如何让我的照片上传成功函数工作。看来这个函数根本就没有被调用。成功函数不是以ajax的形式调用的

请帮助我,如果你知道。

+0

看看这个链接.. http://stackoverflow.com/questions/10899384/uploading-both-data-and-files-in-one-form-using-ajax –

回答

0

你使用jQuery表单插件吗?如果是这样,请确保它的源代码已添加到HTML中并且没有错误地加载。

你的代码看起来不完整,是因为你在$('#upload').on('click',function(){里面还有其他东西吗?如果没有,请确保您关闭功能,这里就是我的意思(我也是固定的缩进):

$('#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(); 
}); 

还要确保insert_url在此代码之前定义。

如果仍然不起作用,控制台是否显示“before”,“che”或“error”?