《学习日记》原生JS写ajax

来源:互联网 发布:淘宝收到假货怎么投诉 编辑:程序博客网 时间:2024/06/08 04:33
<script type="text/javascript">
function myAjax(type,url,data,con,callBack){//type:请求方式  url:请求地址  data:请求的参数  con:是否异步  false代表同步 true代表异步,callBack回调函数
var xmlHttp = new XMLHttpRequest();
if(!con){
if(xmlHttp.onreadyState == 4){
var responseTest = xmlHttp.responseTest();
callBack(responseTest);
}
}
xmlHttp.open("POST","HELLO.jsp",true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");//如果是post就需要自定义请求头
xmlHttp.send(data);//JSON格式  {"name":"hehe"}
}
</script>
0 0
原创粉丝点击