在jquery中添加.ajax会导致页面加载挂起


adding a .ajax to my jquery causes page load to hang

我有一个使用bootstrap和jquery的页面。基本上呈现一张会议与会者的桌子,并允许主持人办理入住手续。主持人也可以添加一个新的与会者,如果他们没有注册(即没有在数据库中)。

我有一个名为Attented的现有工作按钮,它有一个onclick事件,并调用一个php函数来更新DB。这项工作:

<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>

现在我添加了一个模式弹出窗口,要求提供联系信息,然后点击该按钮即可获得功能

<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调用(如摘录中所示),我可以获得模式弹出窗口,填写信息并查看警报。

我打碎了什么???

答案是我的ajax正在与之交谈的实际服务器间歇性停机,因此产生了奇怪的结果。ajax调用有时会成功,有时会挂起或失败。