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('' );
}
},
'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 banklist = new ArrayList();
List> 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配置部分:

  AjaxRequest
  com.servlet.AjaxRequest
 

 
  AjaxRequest
  *.ajax
 

jsp部分:


  • jquery-1.4.2.min.zip (24.2 KB)
  • 下载次数: 0
  • json-lib-2.2.3-jdk15.jar (145 KB)
  • 下载次数: 0

你可能感兴趣的:(ajax,servlet,json,web,ie)