2012-07-11 84 views
0

點擊提交後,我有一個表單更新更多的內容。這部分的所有元素都已經在DOM中。我遇到$ .post的問題,因爲它是異步的,並嘗試切換到$ .ajax,但現在當我單擊表單的這部分單擊提交時,什麼也沒有發生。

不工作:

$.ajax({ 
      type: 'POST', 
      url: 'functions/flow.php', 
      data: { 
       step: 3, 
       id: question_id 
      }, 
      async: false 
     }).done(function(data) { 
      $('#fourth_step .form').append(data); 
     }); 

這工作:

$.post("functions/flow.php", { 
      step: 3, 
      id: question_id 
     }, function(data) { 
      $('#fourth_step .form').append(data); 
     } 
     ); 

我試着用.fail看看,如果我得到一個錯誤,但好像沒有什麼改變,它只是停止。

感謝您的幫助。

+1

? – Petah 2012-07-11 05:41:40

+0

你需要'成功'函數來代替'done' – Jashwant 2012-07-11 05:43:56

+0

@Jashwant依賴於他的jQuery版本(1.7他應該使用'.done')。 – 2012-07-11 05:46:25

回答

1
$.ajax({ 
      type: 'POST', 
      url: 'functions/flow.php', 
      data: { 
       step: 3, 
       id: question_id 
      }, 
      async: false, 
      success:function(data){ 
       $('#fourth_step .form').append(data); 

      } 
}); 
什麼版本的jQuery您使用的是
0
$.ajax({ 
    type: 'POST', 
    url: 'functions/flow.php', 
    data: "step="+3+"&id="+question_id, 
    async: false 
    success: function(data) { 
    $('#fourth_step .form').append(data); 
    } 
}); 
0
$.ajax({ 
    type: 'POST', 
    url: 'functions/flow.php', 
    data: '{"step":3,"id":'+question_id+'}', 
    async: false 
    success: function(data) { 
    $('#fourth_step .form').append(data); 
    } 
}); 
+0

Upvoting您的文章帳戶的系列downvotes,本頁面上的所有解決方案將工作。 – Ohgodwhy 2012-07-11 05:59:03