2013-11-26 63 views
0

我有一個使用引導和jQuery的頁面。基本上提供了一個會議與會者的表格,並允許主持人辦理登機手續。如果主持人尚未註冊(即不在數據庫中),主持人也可以添加新的參與者。添加.ajax到我的jquery導致頁面加載掛起

我有一個名爲Attend的現有工作按鈕,它有一個onclick事件並調用一個php函數來更新數據庫。這個工程:

<script> 
// This is the function that is called when the Arrive button is clicked 
$(function() 
    { 
     $('button#attendedButton').on('click', function (e) { 
      var idFromRow = $(this).data('id'); 
      // Change the color of the button 
      $(this).css('background-color', '#428bca') 
      // Disable the button 
      $(this).prop('disabled', true) 
      // Change the button text 
      $(this).text('Arrived') 
      // Change the cell next this button and mark it as Atten 
      $(this).closest('td').prev().text('Attended') 
      idFromRow = idFromRow + '&action=setAttended' 

      // for testing we can alert the variables 
      //alert(idFromRow) 
      // Call the php function to update the database 

      $.ajax({type: "GET", url:"CheckInFunctions.php", data: idFromRow}) 
      }) 
    } 
) 
</script> 

現在我增加了一個模式彈出它的onclick詢問聯繫信息,然後該按鈕具有此功能

<script> 
// This is the function that is called when the Add button is clicked 
$(function() 
    { 
     $('button#addAttendeeSubmit').on('click', function (e) { 

      fname = document.getElementById ("newAttendeefname").value 
      lname = document.getElementById ("newAttendeelname").value 
      email = document.getElementById ("newAttendeeemail").value 
      note = document.getElementById ("newAttendeeNote").value 
      phone = '111-555-1212' 
      //phone = document.getElementById ("newAttendeefname").value 

      newInfo = 'fname='+fname+'&lname='+lname+'&email='+email+'&phone='+phone+'&note='+note+'&action=addAttendee' 
      // for testing we can alert the variables 
      alert(newInfo) 
      // console.log('here we are in add submit') 
      // Call the php function to update the database 
      //$.ajax({type: "GET", url:"CheckInFunctions.php", data: newInfo}) 
      }) 
    } 
) 
</script> 

奇怪的 - 現在,當我加載頁面(甚至前出現任何彈出窗口)頁面加載掛起 - 如果我註釋掉.ajax調用(因爲它在提取中)頁面加載,我可以獲取模式彈出窗口,填寫信息並查看提醒。

我打破了什麼?

+0

您是否試過使用螢火蟲(或一些類似的開發者工具)來檢查GET-Request是否被髮送,如果是,它返回什麼? – jwulf

回答

0

答案是,我的阿賈克斯談論的實際服務器間歇性地下降 - 因此奇怪的結果。有時Ajax調用會成功,有時會掛起或失敗。