2013-11-28 35 views
0

我正在學習ajax/jQuery,並有一些問題。代碼:Ajax/jQuery?需要幫助來添加參數通過

.click(function() { 
     var periode = 'ALL'; 
     if ($('#registerat input:checked').val() != 'ALL') 
      periode = $('#sdate').val() + '-' + $('#edate').val(); 
      name = $('#merchant'); 
     oTable.fnReloadAjax('reportuserdata.php?ala=' + alaid + '&periode=' + encodeURI(periode)); 
     return false; 
    }); 

我想補充這(從選擇框選擇,這是正確的語法?)參數的reportuserdata.php,也許這樣嗎?

oTable.fnReloadAjax('reportuserdata.php?ala=' + alaid + '&periode=' + encodeURI(periode) + '&merchant' + encodeURI(nama)); 

選擇框:

<select name="merchant" id="merchant"> </select> 

回答

0

嘗試這樣的事情

name = $('#merchant').val(); 

...'&merchant' + encodeURI(name)); 
+0

你需要一個'=' – Barmar

0

首先你需要獲得使用.val()元素的值,那麼只需將它添加到URL,

var name = $('#merchant').val(); 
oTable.fnReloadAjax('reportuserdata.php?ala=' + alaid + '&periode=' + encodeURI(periode) + '&name=' + encodeURI(name)); 
0

Yo你想打電話給商人的.val(),所以你得到的價值,而不只是dom的參考。

0

要在下拉列表中獲取所選值

$('#merchant').val(); 

要獲得在下拉列表中選擇文本

$('#merchant :selected').text();