我是 Javascript 和 jQuery 的新手,对以下代码和结果感到困惑。
为什么我的 golfer_name 在范围内,但我的 team_id 不在范围内?我该如何解决?它似乎是数组,并且变量集等于回调中不可用的数组元素。
jQuery代码
function submit_pick( sender ) {
var names = sender.attr('name').split('-');
var team_id = names[0];
var tournament_id = names[1];
var pick_number = names[2];
var golfer_id = sender.val();
var golfer_name = sender.find("option:selected").text();
var senders_parent = sender.parent().get(0);
sender.remove();
$(senders_parent).html('submitting pick...');
jQuery("#testdiv").append("submit pick before ajax request: "+names+', '+team_id+', '+tournament_id+', '+pick_number+', '+golfer_id+', '+golfer_name+'<br />');
jQuery.post(fantasy_golf.ajaxurl,
{'action' : 'insert_pick',
'team_id' : team_id,
'tournament_id' : tournament_id,
'pick_number' : pick_number,
'golfer_id' : golfer_id
},
function(response) {
if (response) {
jQuery("#testdiv").append("submit pick after response: "+names+', '+team_id+', '+tournament_id+', '+pick_number+', '+golfer_id+', '+golfer_name+'<br />');
}
},
'text'
);
}
#testdiv 的结果
submit pick before ajax request: 10,2,1, 10, 2, 1, 22, Aaron Baddeley
submit pick after response: undefined, undefined, undefined, undefined, 22, Aaron Baddeley