对于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. poj2886 Who Gets the Most Candies?

    思路: 先打反素数表,即可确定因子最多的那个数.然后模拟踢人的过程确定对应的人名.模拟的过程使用线段树优化加速. 实现: #include <cstdio> #include <cs ...

  2. Visual SVN自动给文件加锁

    在使用SVN作为版本控制器的时候,在VS里安装VISUALSVN插件,当修改文件公共文件的时候需要先Get Lock,如果对于多次操作这个鼠标操作显得是一些复杂,自动给文件加锁的操作实际是给文件加一个 ...

  3. redis-cli 工具--raw参数的作用

    最近阅读了以redis官网关于--raw参数的解释,其功能有两个: 1.按数据原有格式打印数据,不展示额外的类型信息 例如:使用命令发送方式(redis在使用时有命令发送方式和交互方式两种)创建一个k ...

  4. 数组(Arry)几个常用方法的详解

    join() 方法用于把数组中的所有元素放入一个字符串.元素是通过指定的分隔符进行分隔的. arrayObject.join(separator)separator 可选.指定要使用的分隔符.如果省略 ...

  5. Android(java)学习笔记191:ContentProvider使用之利用ContentProvider备份和还原手机短信(掌握)

    1. 通过阅读系统源码我们知道: 短信的内容提供者: content://sms/            系统短信的内容提供者的路径 2. 利用ContentProvider备份和还原手机短信: (1 ...

  6. swift 与 @objc

    Objective-C entry points https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-in ...

  7. tf.app.run() got unexpected keyword argument 'argv'

    运行的代码是mnist_with_summaries.py.出现的问题是 tf.app.run() got unexpected keyword argument 'argv' 昨天一直以为是我自己不 ...

  8. js 脚本语言

    字符串转换为数字 parseInt(string) .parseFloat().Number() 参考博客:https://zhidao.baidu.com/question/629898532158 ...

  9. Axure 9 面板折叠显示隐藏

    1  首先放置一个面板1作为点击事件: 2  另外一个面板2或者其他组建,将其设置为动态面板,然后隐藏 3  给面板1添加如下事件,即可: 4  我们点击面板1,可以实现展开隐藏面板2的动态效果

  10. 获取汉字的拼音首字母--pinyin

    var pinyin = (function (){ var Pinyin = function (ops){ this.initialize(ops); }, options = { checkPo ...