Ajax请求以及和IE的兼容

js部分:
function bankmsg(){
var bank = document.getElementById("bank_msg").value;
$.ajax({
'url':'getbanklist.ajax?timeStamp=' + new Date().getTime(),
'type':'post',
'data':'bank_name='+bank,
'contentType': 'application/x-www-form-urlencoded; charset=utf-8',
'dataType':'json',
'success':function(data){
$('#bank_lhh').empty();
for(i = 0;i < data.length;i ++){
var s = data[i];
$('#bank_lhh')
.append('<option value=' + s.bank_lhh
+ '>' + s.bank_name + '</option>' );
}
},
'error':function(){
//服务器处理出错,会执行该函数。
}
});
return true;
}
servlet部分:
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
String uri = request.getRequestURI();
String action = uri.substring(uri.lastIndexOf("/"),uri.lastIndexOf("."));
if(action.equals("/getbanklist")){
String bank_name = request.getParameter("bank_name");
HLog.m_messagelog.debug("bank_name:" + bank_name);
List<BankListTable> banklist = new ArrayList<BankListTable>();
List<ArrayList<String>> list = BankListTable.getBankList(bank_name);
if(list!=null){
for(int i = 0 ;i < list.size(); i ++){
BankListTable s = new BankListTable();
s.setBank_lhh(list.get(i).get(0));
s.setBank_name(list.get(i).get(1));
s.setBank_top(list.get(i).get(2));
banklist.add(s);
}
JSONArray arry = JSONArray.fromObject(banklist);
String jsonStr = arry.toString();
//System.out.println(jsonStr);
out.println(jsonStr);
}
}
}

WEB—INF下的web.xml配置部分:
<servlet>
  <servlet-name>AjaxRequest</servlet-name>
  <servlet-class>com.servlet.AjaxRequest</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>AjaxRequest</servlet-name>
  <url-pattern>*.ajax</url-pattern>
  </servlet-mapping>
jsp部分:
<input type="text" name="bank_msg" id="bank_msg" />
<input type="button" value="查询" onclick="return bankmsg();" />
<select name="bank_lhh" id="bank_lhh" >
<option value="${bank_lhh}">${SettleAccountInfoAlliedBankCode}</option>
</select>

你可能感兴趣的:(json,Ajax,Web,servlet,IE)