对于Ajax核心的东西需要在进行总结提炼一下:

xmlHttp对象。

方法:xml.responseText获取后台传递到前台的数据,经常性的使用var object=xml.responseText;

前端:

二级联动的例子:

 function onloadInfo(){
var shengId=document.getElementById("sheng").value;
shi.options.length=0;//清除市的下拉框内容!
var xmlHttp;
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}else{
xmlHttp=new ActiveXObject( "Microsoft.XMLHTTP ");
}
alert("readState状态:"+xmlHttp.readyState+";status状态:"+xmlHttp.status);
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4&&xmlHttp.status==200){
alert(xmlHttp.responseText);
var object=eval("("+xmlHttp.responseText+")");
for(var i=0;i<object.rows.length;i++){
var o=object.rows[i];
shi.options.add(new Option(o.text,o.id));
}
}
};
xmlHttp.open("get","checkUserName?action=ejld&shengId="+shengId,true);
xmlHttp.send();
}
</script>
<body>
<div>
省:<select id="sheng" onchange="onloadInfo()">
<option value="1">山东省</option>
<option value="2">江苏省</option>
<option value="3">宁夏回族自治区</option>
</select>
市:<select id="shi">
</select>
</div>
</body>
</html>

后台:

 private void ejld(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/Html;charset=utf-8");
PrintWriter out=response.getWriter();
JSONObject resultJson=new JSONObject();
String shengId=request.getParameter("shengId");
JSONArray Jsonarray=new JSONArray();
JSONObject temp=null;
switch(Integer.parseInt(shengId)){
case 1:{
temp=new JSONObject();temp.put("id", 1);temp.put("text", "济南市");Jsonarray.add(temp);
temp=new JSONObject();temp.put("id", 2);temp.put("text", "潍坊市");Jsonarray.add(temp);
temp=new JSONObject();temp.put("id", 3);temp.put("text", "青岛市");Jsonarray.add(temp);
break;
}
case 2:{
temp=new JSONObject();temp.put("id", 4);temp.put("text", "南通市");Jsonarray.add(temp);
temp=new JSONObject();temp.put("id", 5);temp.put("text", "苏州市");Jsonarray.add(temp);
temp=new JSONObject();temp.put("id", 6);temp.put("text", "泰兴市");Jsonarray.add(temp);
break;
}
case 3:{
temp=new JSONObject();temp.put("id", 7);temp.put("text", "银川市");Jsonarray.add(temp);
temp=new JSONObject();temp.put("id", 8);temp.put("text", "吴忠市");Jsonarray.add(temp);
temp=new JSONObject();temp.put("id", 9);temp.put("text", "中卫市");Jsonarray.add(temp);
break;
}
}
resultJson.put("rows", Jsonarray);
out.println(resultJson);
out.flush();
out.close();
}

其中:

对于JSONObject resultJson=new JSONObject();

我们是一个大的对象
里面有一个数组:
JSONArray jsonArray=new JSONArray();
然后还可以继续往里面加对象。
这里面的对象可以有自己的key-value值!
这很有意思!

Ajax核心知识(2)的更多相关文章

  1. Ajax核心知识(1)

    XMLHttpRequest对象创建 所有现代浏览器均支持XMLHttpRequest对象( IE5 和 IE6 使用 ActiveXObject). XMLHttpRequest用于在后台与服务器交 ...

  2. 对学习Ajax的知识总结

    1.对Ajax的初步认识 1.1. Ajax 是一种网页开发技术,(Asynchronous Javascript + XML)异步 JavaScript 和 XML: 1.2.Ajax 是异步交互, ...

  3. 网络基础知识、ASP.NET 核心知识(1)*

    为什么要写网络? 我原本的计划是这样的,连续两天梳理ASP.NET开发的核心知识.说到这呢,有人问了.“不是说好了做ASP.NET笔记吗?为啥要写网络基础知识?是不是傻?” 原因是这样的.作为网站开发 ...

  4. AJAX重点知识的心得体会

    下面就为大家带来一篇 AJAX重点知识的心得体会.学习还是有点帮助的,给大家做个参考吧. AJAX是什么? 是Asynchronous Javascript And XML的首字母的缩写, 它不是一门 ...

  5. Ajax基础知识 浅析(含php基础语法知识)

    1.php基础语法    后缀名为.php的文件 (1) echo   向页面中输入字符串  <?php    所有php相关代码都要写在<?php ?>这个标签之中 echo &q ...

  6. Ajax基础知识《一》

    对于网站开发人员,一定不会陌生的Ajax技术,本篇就让我们认识一下它,或许在日后的开发过程中我们就可以使用到.Ajax在那方面使用的比较多呢?答案:表单注册,传统的表单注册,有时需要填写大量的信息,当 ...

  7. ASP.NET Ajax核心对象

    本章学习目标 主要掌握AJAX的基本概念和实现机制,学习并创建XMLHttpRequest对象,使用XMLHttpRequestObject对象获取服务器端的数据 主要内容如下,请点击ASP.NET ...

  8. Ajax基础知识(二)

    接上一篇  Ajax基础知识(一) 在上一篇博客里,抛弃了VS中新建aspx页面,拖个button写上C#代码的方式.使用ajax的方式,异步向服务器请求数据.我们让服务器只简单的返回一个" ...

  9. Vuex核心知识(2.0)

    Vuex 是一个专门为 Vue.js 应该程序开发的状态管理模式,它类似于 Redux 应用于 React 项目中,他们都是一种 Flux 架构.相比 Redux,Vuex 更简洁,学习成本更低.希望 ...

随机推荐

  1. IIS中不让下级应用程序继承主域名的web.config配置

    <location path="." allowOverride="true" inheritInChildApplications="fals ...

  2. AJPFX关于增强for的概述和使用(foreach)

    增强for的概述和使用(foreach)1.增强for的概述和使用(foreach)                格式:                for(数组或者Collection集合中元素 ...

  3. 11 DOM基础

    1.css   标签 js       元素 dom    节点,元素节点,属性节点,文本节点 2.dom浏览器支持率 ie      10% chrome   60% FF       99% 3. ...

  4. 使用Jenkins进行android项目的自动构建(4)

    加入单元测试 android单元测试很多都是使用Instrumentation进行的,这里讲的是试用JUnit,为什么用JUnit呢?因为使用Instrumentation需要打包apk安装,然后再进 ...

  5. struts2的action是线程安全的,struts1的action不是线程安全的真正原因

    为什么struts2的action是线程安全的,struts1的action不是线程安全的? 先对struts1和struts2的原理做一个简单的讲解 对于struts1 ,当第一次**.do的请求过 ...

  6. FlowNet: Learning Optical Flow with Convolutional Networks

    作者:嫩芽33出处:http://www.cnblogs.com/nenya33/p/7122701.html 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须 ...

  7. 基于ANGULAR.JS的下一代WEB应用开发-01-yeoman

    Angularjs 个人认为这是一款很好的框架!它将我们从AJAX应用的开发中解救了出来!嗯....废话就说道这里下面我们开始把! 首先我们必须了解一些核心的概念: 客户端模版 MVC 数据绑定 依赖 ...

  8. git 出现 The current branch is not configured for pull No value for key branch.master.merge found in configuration

    以下是我在网上找到的不错的文章,我参考后已解决我的问题: http://my.oschina.net/robinsonlu/blog/144085 http://www.cnblogs.com/zha ...

  9. 迅为i.MX6Q嵌入式开发板

    工业级核心板:核心板10层高速PCB设计,充分保证电磁兼容. 01. 处理器:开发板默认是四核商业扩展级芯片,可根据用户需求更换单核.双核.工业级.汽车级处理器,批量更省成本. 02. 扩展引脚:32 ...

  10. swift 使用计算属性+结构管理内存

    class GooClass { deinit { print("aaaaaaaa") } var str = "gooClass" } struct GooS ...