表单没有通过jQuery的ajax POST提交

时间:2013-02-26 17:48:30

标签: ajax jquery

我正在尝试通过jQuery的ajax函数提交表单,如下所示:

$("form#game_submit").submit(function(){   
var away = $("#away_score").val();
var home = $("#home_score").val();
var game = "1148";
var home_team = "Cleveland Cavaliers";
var away_team = "Orlando Magic";
var home_short = "Cavaliers";
var away_short = "Magic";
var date = "463";
var league = "nba";

if(away != home
&& is_numeric(home)
&& is_numeric(away))
{        
    $.ajax({  
        type: "POST",  
        url: "/model/ajax/game_predictions_submit.php",  
        data: ({
            away_score: away,
            home_score: home,
            away: away_team, 
            home: home_team, 
            game: game,
            date: date,
            league: league
        }),
        success: function()
        {
            if(away > home)
            {
                var winner = away_team;
                var loser = home_team;

                var winner_short = away_short;
                var loser_short = home_short;

                var win_score = away;
                var lose_score = home;
            }

            if(home > away)
            {
                var winner = home_team;
                var loser = away_team;

                var winner_short = home_short;
                var loser_short = away_short;

                var win_score = home;
                var lose_score = away;
            }

            if(league == "ncaa")
            {
                var win_img = winner_short;
                var lose_img = loser_short;
            }

            if(league != "ncaa")
            {
                var win_img = winner;
                var lose_img = loser;
            }

            alert(hi);
            $('#away_score').attr('readonly', true);
            $('#home_score').attr('readonly', true);
            return false;
        } 
    });   
}
return false;
});

HTML如下:

<form id='game_submit'>
    <input type='text' name='away_team' maxlength='3' id='home_score' class='bar' style='width:30px;top:0px;' autocomplete='off'  value='0'/>
    <input type='text' name='away_team' maxlength='3' id='away_score' class='bar' style='width:30px;top:0px;' autocomplete='off'  value='0'/>

    <button class='minimal' id='game_submit_button' style='float:right;'>Save</button>
</form>

我已经尝试了解Chrome浏览器的javascript控制台中存在的问题,但它并没有给我带来任何错误。可以找到一个工作示例here

1 个答案:

答案 0 :(得分:0)

尝试不使用isNaN(不是数字)

if(away != home
&& !isNaN(home)
&& !isNaN(away))
{