Ajax異步url傳參問題

 

今天發現的一個關於ajax url傳值時,獲取下拉列表選項的value時容易碰到的問題:java

 

 

 

/**異步提交**/
var xmlHttp;
function selectListResult(){
	var f=document.selectForm;
	var branch=f.selectbranch.value;
	var depart=f.selectdepart.value;
	var name=f.UserName.value;
	var time=f.Time.value;  	
	var url=${basePath}"findScheduleByManyAction.action?BId="+branch+"&DId="+depart+"&UserName="+name+"&Time="+time;
	alert(url);
	xmlHttp=createXMLHttpRequest();
	/*設置回調函數*/
	xmlHttp.onreadystatechange=processRequest;
	/**打開鏈接*/
	xmlHttp.open("GET",url,true);
	/**發送請求*/
	xmlHttp.send(null);
}

 

 

 

這是jsp頁面,動態獲取值時,<option value="${branchid}"> 和<option value="branchid">在運行時均可以 取出值,可是Ajax獲取value="${branchid}"的值是一個int數值,Ajax獲取value="branchid"的值時倒是 "branchid" 這個字符串,因此用到Ajax時須要用到EL表達式取值。ajax

 

 

<td width="261" height="37">選擇機構:
            <select name="selectbranch">
            <option value="0">=不限=</option>
            <s:iterator value="branchList">
             <option value="${branchid}"><s:property value="branchshortname"/></option>
            </s:iterator>
            </select>
          </td>

<td width="261" height="37">選擇機構:
            <select name="selectbranch">
            <option value="0">=不限=</option>
            <s:iterator value="branchList">
             <option value="branchid"><s:property value="branchshortname"/></option>
            </s:iterator>
            </select>
          </td>
相關文章
相關標籤/搜索