js ajax请求
javascript/js的ajax的POST请求:
<script type="text/javascript">/* 创建 XMLHttpRequest 对象 */var xmlHttp;function GetXmlHttpObject(){ if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp;}// -----------ajax方法-----------//function getLabelsPost(){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert('您的浏览器不支持AJAX!'); return; } var url="http://www.lifefrom.com/t/"+Math.random(); xmlhttp.open("POST",url,true);<strong>//true表示</strong><code class="html plain">异步,false表示同步 xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); //设置header的Context-Type为application/x-www-form-urlencode确保服务器知道实体中有参数变量
xmlhttp.send(); xmlHttp.onreadystatechange=getLabelsOK;//发送事件后,收到信息了调用函数}function getOkPost(){ if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3){ // 本地提示:加载中/处理中 } if (xmlHttp.readyState==4 && xmlHttp.status==200){ var d=xmlHttp.responseText; // 返回值 // 处理返回值 }}</script> javascript/js的ajax的GET请求:<script type="text/javascript">/* 创建 XMLHttpRequest 对象 */var xmlHttp;function GetXmlHttpObject(){ if (window.XMLHttpRequest){ // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp;}// -----------ajax方法-----------//function getLabelsGet(){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert('您的浏览器不支持AJAX!'); return; } var id = document.getElementById('id').value; var url="http://www.lifefrom.com?id="+id+"&t/"+Math.random(); xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange=favorOK;//发送事件后,收到信息了调用函数 xmlHttp.send(null);//对于get方法由于参数放在url上,因此这里直接send(null)即可。post传递相关的参数即可} function getOkGet(){ if(xmlHttp.readyState==1||xmlHttp.readyState==2||xmlHttp.readyState==3){ // 本地提示:加载中 } if (xmlHttp.readyState==4 && xmlHttp.status==200){ var d= xmlHttp.responseText; // 处理返回结果 }}</script>相关推荐
坚持着执着 2020-07-16
坚持着执着 2020-06-14
lyqdanang 2020-08-16
坚持着执着 2020-06-16
TONIYH 2020-06-05
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
curiousL 2020-08-03
时光如瑾雨微凉 2020-07-19
jiaguoquan00 2020-07-07