常见的ajax响应的数据类型:json和xml 、text/html
常见ajax传递参数
get:
需要给元素绑定 onclick(函数名(参数值)) 事件
<a href="" id="delete" onclick="f({{12}})">删除</a>
函数:
函数名(形参){
路由传递值得时候 凭借 +形参
}
<script type="text/javascript">
function f(id) {
var xhr=new XMLHttpRequest();
xhr.open("get",'/ajax/canshu/'+id);
xhr.send();
xhr.onload=function () {
//输出json数据
// console.log(xhr.responseText);
//将json字符串转换为json对象
var res=xhr.responseText;
var jsonObj=JSON.parse(res);
console.log(jsonObj);
}
}
这样就可以实现 get传值