简体   繁体   English

Ajax发布不会向控制器发送值

[英]Ajax post doesn't send value to controller

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. 我想做的第一件事是一个api请求,对于它返回的每个数组,我都希望它对我的控制器方法进行发布。 It finds the method but sends null to it instead of the value of gameID. 它找到方法,但向其发送null而不是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. 所有console.log都为我提供了正确的值,无论类型是字符串还是gameID在发布之前和成功之后都是正确的。 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;
                }
            });
        });
    }

})

On your second ajax request, the data parameter is not provided: 在您的第二个ajax请求中,未提供data参数:

$.ajax({    
      data: {gameID: gameID}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM