Question

Ive been debugging this method the whole day. I need some help with this. The first thing i want to do is a api-request and for every array it returns i want it to make a post to my controller method. It finds the method but sends null to it instead of the value of gameID. All console.log gives me the right value both the type wich is string and the gameID is correct both before the post and on the success. What am i doing wrong?

var date = "02/13/2014";

$.ajax({
    dataType: "jsonp",
    type: "post",
    crossDomain: true,
    url: 'http://stats.nba.com/stats/scoreboard/?LeagueID=00&gameDate=' + date + '&DayOffset=0',
    success: function (val) {
        var result = val.resultSets[0].rowSet;
        $.each(result, function (key, value) {
            var gameID = this[2];
            console.log(gameID);
            console.log(typeof(gameID));
            $.ajax({
                async: false,
                type: "post",
                url: "/Stats/addGame",
                gameID: JSON.stringify(gameID),
                done: function (data) {
                    console.log(gameID);
                    console.log(typeof(gameID));
                    console.log(data);
                    var a = data;
                },
                error: function (jqXHR, err) {
                    console.log(err);
                    console.log(gameID);
                    var e = err;
                }
            });
        });
    }

})
Était-ce utile?

La solution

On your second ajax request, the data parameter is not provided:

$.ajax({    
      data: {gameID: gameID}
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top