惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
V
Visual Studio Blog
NISL@THU
NISL@THU
S
Security Affairs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
The Register - Security
The Register - Security
博客园_首页
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
T
Tor Project blog
有赞技术团队
有赞技术团队
美团技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Google Online Security Blog
Google Online Security Blog
Vercel News
Vercel News
Webroot Blog
Webroot Blog
S
Security @ Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
DataBreaches.Net
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
T
Troy Hunt's Blog
C
Check Point Blog
D
Docker
Latest news
Latest news
Martin Fowler
Martin Fowler
T
Tenable Blog

博客园 - 右手边

C#动态执行代码 这是一个广为流传的关于项目管理的通俗讲解 [史上最狂妄的演讲]你不服都不行<英汉版>~~ - 右手边 - 博客园 关于页面动态添加控件 利用反射动态创建对象 使用反射技术动态创建类对象(实例代码) 利用反射来动态创建实例和调用方法(上) 基于ASP.NET的Web动态控件创建 家中请客(最佳ERP教材)- - 2007年4月25日 经典的几句英文 网上英语免费杂志在钱订阅网址 将(Oracle)数据库表导出到Excel,并生成文件(C#实现) B/S结构与C/S结构 Ajax简单例子 Oracle 启动与关闭例程 AJAX的原理 VB资料库-无限下载 ASP.Net中程序构架与程序代码的分离 Oracle 系统结构
AJAX三步走
右手边 · 2007-05-22 · via 博客园 - 右手边

ajax 简单 例子,共三步。

例子涉及到本地的数据库,故不能在你本地正常运行,但思路是对的

第一步:(通用) 把下面的代码写入一个ajax.js文件中,send_request()方法有5个参数,
1,提交的方法;
2,url,也可以通过它传递参数;
3,只是参数;
4,返回类型,text或xml;
5,回调函数的方法名称。
var http_request = false;

//send
function send_request(method,url,content,responseType,callback){
 http_request = false;
 if(window.XMLHttpRequest){
  http_request = new XMLHttpRequest();
  if(http_request.overrideMimeType){
   http_request.overrideMimeType("text/xml");   
  }
 }else if(window.ActiveXObject){
  try{
   http_request = new ActiveXObject("Msxm12.XMLHTTP");
  }catch (e){
   try{
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
   }catch (e){
    
   }
  }
 }
 if(!http_request){
  window.alert("E XMLHttpReqeust");
  return false;
 }
 if(responseType.toLowerCase() == "text"){
  //http_request.onreadystatechange = processTextResponse;
  http_request.onreadystatechange = callback;
 }else if(resposeType.toLowerCase() == "xml"){
  //http_request.onreadystatechange == processTextResponse;
  http_request.onreadystatechange = callback;
 }else{
  window.alert("E1");
  return false; 
 }
 
 if(method.toLowerCase() == "get"){
  http_request.open("GET",url,true);
 }else if(method.toLowerCase() == "post"){
  http_request.open("POST",url,true);
  http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
 }else{
  window.alert("E2");
 }
 http_request.send(content);
}

//Text
function processTextResponse(){
 if(http_request.readyState == 4){
  if(http_request.status == 200){
   document.form1.rs.value = http_request.responseText;
  }else{
   alert("E3");
  }
 }
}

//XMl
function processXMLRequest(){
 if(http_request.readyState == 4){
  if(http_request.status == 200){
   document.form1.rs.value = http_request.responseText;
  }else{
   alert("E4");
  }
 }
}

第二步:把此脚本放入页面(通用)

<script language="javascript">
 //取组下的3个clip
 function update(type,id) {
  var f = document.p;
  if("clip" == type){
    one.innerHTML = "  正在处理请求的内容 <img src='/images/icon/loading.gif'></img>";
    send_request("GET","/common2/query.jsp?groupbyclip_id="+id,null,"text",processTextResponse_one);
  }
  var f = document.p;
  if("cpid" == type){
    one.innerHTML = "  正在处理请求的内容 <img src='/images/icon/loading.gif'></img>";
    send_request("GET","/common2/query.jsp?cp_id="+id,null,"text",processTextResponse_one);
  }
 }

</script>

第三步:创建jsp处理页面,接受参数,处理,out.print()输出就可以了,回调函数会接收到打印出的内容(根据业务需求作相应的修改<%
 //根据省id获取城市列表
 if(request.getParameter("province_id") != null &&request.getParameter("province_id") != "-1"){
  ArrayList provinceList = new ArrayList();
  try{
   provinceList = Factory.db_city.queryByProvinceId(Integer.parseInt(request.getParameter("province_id")));
  }catch(Exception e){
   out.print("根据省查找city出错");
  }
  if(provinceList != null){
   out.println("<select name='city' id='city' onchange=\"update('city')\">");
   out.println("<option value='-1'>请选择城市</option>");
   for(int i=0;i<provinceList.size();i++){
    CityBean cityBean = (CityBean)provinceList.get(i);
    out.println("<option value="+cityBean.getCity_id()+">"+cityBean.getCity()+"</option>");           
   }
   out.print("</select>");
  }
 }
 
 //根据city_id查询区县
 if(request.getParameter("city_id") != null &&request.getParameter("city_id") != "-1"){
  ArrayList districtList = new ArrayList();
  try{
   districtList = Factory.db_district.queryByCityId(Integer.parseInt(request.getParameter("city_id")));
  }catch(Exception e){
   out.print("根据省查找district出错");
  }
  if(districtList != null){
   out.println("<select name='district' id='district'>");
   out.println("<option value='-1'>请选择区县</option>");
   for(int i=0;i<districtList.size();i++){
    DistrictBean districtBean = (DistrictBean)districtList.get(i);
    out.println("<option value="+districtBean.getDistrict_id()+">"+districtBean.getDistrict()+"</option>");           
   }
   out.print("</select>");
  }
 }
 %>