2015-04-05 38 views
1

我有這樣的代碼JS:

$(document).on("click", "#nextMonth", function(e) 
{ 
    $.post(
    'ajax/genererCalendrier.php', 
    { 
     "mois":mois, "annee":annee 
    }, 
    function(data) 
    { 
     data = jQuery.parseJSON(data); 
    }).success(function() 
    { 
     $('#divCalendrier').html(calendrier); 
     $.ajax(
     { 
     url: 'ajax/genererCalendrier.php', 
     type: 'POST', 
     data: 
     { 
      'action':'rafraichir_nombre_jours_conges' 
     }, 
     dataType:'text', 
     success: function(retour_php) 
     { 
      alert(retour_php); 
     }, 
     error: function() 
     { 
      alert("pas ok"); 
     } 
     }); 
    }).error(function() 
    { 
     $('#divCalendrier').html('<p class="error">Erreur lors de la requête AJAX</p>'); 
    }); 
}); 

此警報不啓動:

alert(retour_php); 

是我的代碼($就到$。員額)是正確的?

我沒有螢火蟲的錯誤。

+3

檢查錯誤控制檯,如果你得到任何錯誤消息。 – Guffa 2015-04-05 13:38:45

+0

我在控制檯中沒有錯誤。 – beegees 2015-04-05 13:39:59

+0

請使用正確的縮進並重新檢查您的代碼。我沒有看到'$(document).ready(function(){..' – 2015-04-05 13:46:35

回答

1

我不明白你的JavaScript的邏輯。如果你正在使用的語法如下:

$.post(
    'ajax/genererCalendrier.php', 
    { 
    "mois":mois, "annee":annee 
    }, 
    function(data) 
    { 
     data = jQuery.parseJSON(data); 
    }) 

您已經有success處理程序,並success event doesn't fire at all! I suggest you add alert`消息在功能上,像這樣:

$.post(
    'ajax/genererCalendrier.php', 
    { 
    "mois":mois, "annee":annee 
    }, 
    function(data) 
    { 
     data = jQuery.parseJSON(data); 
     alert(data); 
    }) 

我敢肯定你會得到的消息一切都會奏效。所以,你的代碼應該是這樣的:

$.post(
    'ajax/genererCalendrier.php', 
    { 
    "mois":mois, "annee":annee 
    }, 
    function(data) 
    { 
    data = jQuery.parseJSON(data); 
    $('#divCalendrier').html(calendrier); 
    $.ajax(
    { 
     url: 'ajax/genererCalendrier.php', 
     type: 'POST', 
     data: 
     { 
     'action':'rafraichir_nombre_jours_conges' 
     }, 
     dataType:'text', 
     success: function(retour_php) 
     { 
     alert(retour_php); 
     }, 
     error: function() 
     { 
     alert("pas ok"); 
     } 
    }); 
    }, 
    error:function() 
    { 
    $('#divCalendrier').html('<p class="error">Erreur lors de la requête AJAX</p>'); 
    }) 

Complete $.post documentation