2012-04-01 76 views
-1

我有這個簡單的代碼使用get方法在多事件中通過jquery執行ajax調用?

$(function(){ 
    $("#Right").click(function(){ 
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: "5" 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 
    $('#block').change(function(){  
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: $(this).attr('value') 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 
}); 

此代碼的工作,只有1問題加載圖像只顯示點擊按鈕,但不工作時,同時改變了選擇菜單,但Ajax加載其他PHP頁面數據調用數據,而不在這兩個事件沒有問題 我的問題,我試着撥打一次數據的頁面加載,因爲現在它表明沒有結果,直到我的選擇菜單 內點擊按鈕或改變的選擇我想這碼

$(function(){ 
    $(document).ready(function(){ 
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: "5" 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 


    $("#Right").click(function(){ 
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: "5" 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 

    $('#block').change(function(){  
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: $(this).attr('value') 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 
}); 

但這不是在它的工作都 我嘗試過其他的東西

$(function(){ 
    $.get("modules/plugins.php",{ 
     count: "5" 
    },function(data) { 
     $('#testid').html(data); 
    }); 

    $("#Right").click(function(){ 
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: "5" 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 

    $('#block').change(function(){  
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: $(this).attr('value') 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 
}); 

既不代碼工作 另外2份還是沒有問題的工作 唯一的問題時,頁面加載沒有結果出現

+1

你可以通過最小化啓動碼。它恐嚇潛在的答案..反應 – Joseph 2012-04-01 22:53:59

+1

你有太多的問題,沒有被標記爲回答 – 2012-04-01 23:06:05

+0

對不起,現在我認爲它的罰款 – Marco 2012-04-01 23:16:58

回答

2

在假設$(this)正在正確地分配給你的下拉它有正確分配一個值(你可以調試或檢查的console.log),你應該改變:

$(this).attr('value')

$(this).val()

您可以實際使用this.value如果它不需要變成一個jQuery對象的任何具體原因

$(function(){ 
    $("#Right").click(function(){ 
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: "5" 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 
    $('#block').change(function(){  
     $("#testid").html('<img src="theme/gfx/loading.gif">').fadeIn(400); 
     $.get("modules/plugins.php",{ 
      count: this.value //  <---- change here 
     },function(data) { 
      $('#testid').html(data); 
     }); 
    }); 
});