Ajax Post无法在Mozilla Firefox中运行

时间:2015-08-29 07:27:31

标签: php ajax mozilla

我有一个网站,当用户点击更新时,我将需要更新的所有值发送到运行UPDATE数据库查询的php页面。我使用Ajax将数据传输到php页面。此更新适用于Chrome和Internet Explorer,但它不适用于Mozilla。我跑了萤火虫,意识到这个请求甚至没有发给服务器,我也不知道为什么

这是我的Ajax代码

$(function() {
            $("#editGameBtn").click(function(){
                var gameId = $('#editGameId').val();
                var newTime = $('#editTime').val();
                var newDate = $('#editDate').val();
                var newGround = $('#editGround').val();
                var newHomeTeam = $('#editHomeTeam').find(":selected").text();
                var newAwayTeam = $('#editAwayTeam').find(":selected").text();

                   if(gameId === "" || newTime === "" || newDate === "" || newGround === ""|| newHomeTeam === ""|| newAwayTeam === "" )
                   {
                       alert("Please Select A game to Edit");
                   }
                    else{
                        $.ajax({
                            type: "POST",
                            url: "updateGame.php",
                           data: { gameId: gameId , newTime: newTime, newDate: newDate, newHomeTeam: newHomeTeam, newAwayTeam: newAwayTeam, newGround: newGround}
                          }).done(function(msg) {
                                alert( "Data Saved: " + msg );
                          });
                    }

            });
        });

1 个答案:

答案 0 :(得分:0)

想出一种方法来解决它,但不知道错误是什么以及为什么解决方案会修复它。希望有人可以解释我所做的更改是如何修复错误的。无论如何,所以我所要做的就是preventDefault,一切正常。

以下是代码的工作版本

$(function() {
    $("#editGameBtn").click(function(e){
        var gameId = $('#editGameId').val();
        var newTime = $('#editTime').val();
        var newDate = $('#editDate').val();
        var newGround = $('#editGround').val();
        var newHomeTeam = $('#editHomeTeam').find(":selected").text();
        var newAwayTeam = $('#editAwayTeam').find(":selected").text();
        e.preventDefault();
           if(gameId === "" || newTime === "" || newDate === "" || newGround === ""|| newHomeTeam === ""|| newAwayTeam === "" )
           {
               alert("Please Select A game to Edit");
           }
            else{
                $.ajax({
                    type: "POST",
                    url: "updateGame.php",
                    data: { gameId: gameId , newTime: newTime, newDate: newDate, newHomeTeam: newHomeTeam, newAwayTeam: newAwayTeam, newGround: newGround}

                  }).done(function(msg) {
                       window.location.reload(true);
                  });
            }

    });
});