您的xhr变量位于click事件发生时调用的函数内部。
调用中止方法时,
xhr不是用于post方法的变量。
xhr变量必须在绑定到click事件的函数的外部,否则在检查其他click事件时将是未定义的。
此外,由于您可能需要多个xhr变量来存储不同的帖子,因此您应该创建一个数组或对象来存储不同的帖子。
var xhr = [];$('.methods a').click(function(){ // do something global to the anchors, eg : change the bg color, etc // set the target container var target = $(this).attr('href'); //if user clicks fb_method buttons if($(this).hasClass('fb_method')){ //do ajax request (add the post handle to the xhr array) xhr.push( $.post("/ajax/get_fb_albums.php", function(msg) { $(target).html('').append(msg).fadeIn(); }) ); }else{ //abort ALL ajax request for ( var x = 0; x < xhr.length; x++ ) { xhr[x].abort(); } $(target).fadeIn(); } return false;});


