var xmlhttp;
if (window.XMLHttpRequest){
//code for IE7+,Firefox,Chrome,Opera,Safari
xmlhttp = new XMLHttpRequest();
)else{
∥code for IE6,IE5
xmlhttp new = ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","url");
xmlhttp.send(O;∥发送请求
xmlhttp.onreadystatechange function (){
if(xmlhttp.readyState ==4 && xmlhttp.status ==200){
alert(xmlhttp.responseText);
}
<script src="js/axios-0.18.0.js"></script>
axios({
method:"get",
url:"http://localhost:8080/ajax-demo1/aJAXDemo1?username=zhangsan"
}).then(function (resp){
alert(resp.data);
})
axios((
method:"post",
url:"http://localhost:8080/ajax-demo1/aJAXDemo1",
data:"username=zhangsan"
}).then(function (resp){
alert(resp.data);
}:
axios.get("url")
.then(function (resp){
alert(resp.data);
});
axios.post("ur","参数")
.then(function(resp){
alert(resp.data);
}
var变量名={
"key1":value1,
"key2":value2,
...
};
value 的数据类型为:
数字(整数或浮点数)字符串(在双引号中)逻辑值(true 或 false)数组(在方括号中)对象(在花括号中)null
var json {
"name":"zhangsan",
"age":23,
"addr":["北京","上海","西安]
};
变量名.key
json.name
<dependency>
<groupld>com.alibaba</groupld>
<artifactld>fastjson</artifactld>
<version>1.2.62</version>
</dependency>
2.Java 对象转 JSON
String jsonStr = JSON.toJSONString(obj);
3.JSON 字符转转 Java 对象
User user = JSON.parseobject(jsonStr,User.class);