问题描述
我知道用ajax,我的思路是用一个一般处理程序返回值付给lable控件。但我不知道怎么写ajax,求教大家,源码带注释我已经写了一段functionsendReuest(xmlHttp){try{xmlHttp=newXMLHttpRequest();}catch(e){try{xmlHttp=newActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlHttp=newActiveXObject("Microsoft.XMLHTTP");}catch(e){alert("您的浏览器不支持");returnfalse;}}}}
解决方案
解决方案二:
如LABEL控件ID为LABEL1,引用JQUERY后$(document).ready(function(){$.ajax({url:"xxxxx",//批处理地址type:"post",//个人喜欢post,也可用getdata:{},//如需要带参数以JSON格式加在这里dataType:"html",//因为不知道批处理返回是否是JSON,直接用HTML了,假设返回时string格式success:function(data){$("#<%=Label1.ClientID%>").html(data);}})})
解决方案三:
ajax固定的语法,怎么不会用呢
解决方案四:
引用2楼bdmh的回复:
ajax固定的语法,怎么不会用呢
没有接触过以前
解决方案五:
不怎么用,友情帮顶接分
解决方案六:
w3c学习一下。
解决方案七:
1楼已经写出来了。
解决方案八:
你的代码完全一行都不用写,用jQuery用$ajax5个字符就实现了完全相同的功能。
解决方案九:
引用7楼devmiao的回复:
你的代码完全一行都不用写,用jQuery用$ajax5个字符就实现了完全相同的功能。
具体代码展示下
解决方案十:
functionshowHint(str){varxmlhttp;if(str.length==0){document.getElementById("txtHint").innerHTML="";return;}if(window.XMLHttpRequest){xmlhttp=newXMLHttpRequest();}else{xmlhttp=newActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200){document.getElementById("txtHint").innerHTML=xmlhttp.responseText;}}xmlhttp.open("GET","test.aspx?q="+str,true);xmlhttp.send();}xmlhttp.responseText是响应的数据,document.getElementById("txtHint")在页面中确定某个控件。这是一个简单的例子,你参考看看。
解决方案十一:
functionloadXMLDoc(){varxmlhttp;if(window.XMLHttpRequest){xmlhttp=newXMLHttpRequest();}else{xmlhttp=newActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200){document.getElementById("myDiv").innerHTML=xmlhttp.responseText;}};xmlhttp.open("POST","test.aspx",true);xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send("name=wang&place=beijing");}这个是post传值,上面的是get方式传值。