2016-10-01 77 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」?