2012-07-30 65 views
2

我有這樣的代碼:jQuery的形式插件沒有顯示出成功的功能

$(".myform").live('submit', function(e){ 
    var options = { 
     target: '.ajaxMessage', 
     // target element(s) to be updated with server response 
     beforeSubmit: showRequest, 
     success: function(data) { 
      alert(data); 
      //$('#dialog-confirm').dialog('close'); 
      //$(".ajaxMessage").html(data).show().delay('5000').fadeOut("5000"); 
     }, 
     type: 'POST' 

$(".myform").ajaxForm(options);

Firefox的控制檯顯示此爲響應

Response 

1{"code":"OK"} 

我的數據被插入到數據庫中正確,但我無法在Firefox控制檯中調用該成功功能,我通過成功消息模板獲得期望的響應,

+2

'$ .live()'不推薦使用。就這樣你知道。改爲使用'$ .on()'或'$ .delegate()'。 – 2012-07-30 02:54:09

+0

但網站說生活應該仍然有效 – user825904 2012-07-30 03:04:15

+0

「已棄用」'!='「不起作用」。在這種情況下,它意味着*嘗試別的東西,因爲很快它將不可用*。 – 2012-07-30 03:05:35

回答

0

嘗試,並分享一些你的代碼或使用的jsfiddle代碼共享,anywayz我假設我正在共享代碼,希望工程爲雅:

$(".myform").on('submit', function(e){ 
    var options = { 
     target: '.ajaxMessage', 
     // target element(s) to be updated with server response 
     beforeSubmit: showRequest, 
     success: function(data) { 
      alert(data); 
      //$('#dialog-confirm').dialog('close'); 
      //$(".ajaxMessage").html(data).show().delay('5000').fadeOut("5000"); 
     }, 
     error: function(){ 
     alert('Error!!!') 
     }, 
     type: 'POST' 
    } 
});