$("#TextBoxID").blur(function(){$.post{ "Handle.ashx", { //Add post data you want,like paramterName:parameterValue,for example Name:'Tim' }, function(data){ //Do something you want },'json' }; });Handle.ashx public void ProcessRequest(HttpContext context) { this.context = context; context.Response.ContentType = "text/plain"; context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.Write(context.Request["Name"]); }
你如个去网上找AJAX的例子或者是资料的话,我想,你可以对付这个例子的。
了解一下AjaxPro,很不错。 简单给你例子 [AjaxPro.AjaxMethod] [AjaxPro.AjaxNamespace("MyAjax")] public class ajax { public void deleteAll(string id) { (new announcesBLL()).Delete(Convert.ToInt32(id)); ToIO.Delete("../shtml/view/View_" + id + ".shtml"); } } <script type="text/javascript"> function deleteAll() { var all = document.getElementsByTagName("input"); if(confirm('确定删除?')) { for(var i=0;i<all.length;i++) { if(all[i].checked) { MyAjax.deleteAll(all[i].name); } } location.href="./admin_view_list.aspx"; } } </script>
写错了,这样才对 [AjaxPro.AjaxNamespace("MyAjax")] public class ajax { [AjaxPro.AjaxMethod] public void deleteAll(string id) { (new announcesBLL()).Delete(Convert.ToInt32(id)); ToIO.Delete("../shtml/view/View_" + id + ".shtml"); } }贴错
onblur var xmlHttp; function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } }function checkuser(){ createXMLHttpRequest(); var a= document.getElementById("txt").value; url = "Handler/a.ashx?a=" + a+ "&t=" + (new Date()).getTime(); xmlHttp.open("GET", encodeURI(url), true); xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { } } xmlHttp.send(null); }
看看这段代码吧
在你的onblur时间中调用GetMessage方法
路径传值如下:url=你当前页的路径/方法名
我能说的就只有这些了
<script language="javascript" type="text/javascript">
var xmlHttp;
//根据浏览器实例化xmlHttp对象
function CreateXmlHttp()
{
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch(e)
{
try{
//IE6+
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try{
//IE5.5
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
}
function SubmitReady()
{
if(xmlHttp.readyState ==4)
{
document.getElementById("elementId").innerHTML=xmlHttp.responseText;
//xmlHttp.responseXML.documentElement.text;
}
}
function GetMessage(url)
{
CreateXmlHttp();
xmlHttp.onreadystatechange=SubmitReady;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
</script>
"Handle.ashx",
{
//Add post data you want,like paramterName:parameterValue,for example
Name:'Tim'
},
function(data){
//Do something you want
},'json'
};
});Handle.ashx
public void ProcessRequest(HttpContext context)
{
this.context = context;
context.Response.ContentType = "text/plain";
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Write(context.Request["Name"]);
}
简单给你例子
[AjaxPro.AjaxMethod]
[AjaxPro.AjaxNamespace("MyAjax")]
public class ajax
{
public void deleteAll(string id)
{
(new announcesBLL()).Delete(Convert.ToInt32(id));
ToIO.Delete("../shtml/view/View_" + id + ".shtml");
}
}
<script type="text/javascript">
function deleteAll()
{
var all = document.getElementsByTagName("input");
if(confirm('确定删除?'))
{
for(var i=0;i<all.length;i++)
{
if(all[i].checked)
{
MyAjax.deleteAll(all[i].name);
}
}
location.href="./admin_view_list.aspx";
}
}
</script>
[AjaxPro.AjaxNamespace("MyAjax")]
public class ajax
{
[AjaxPro.AjaxMethod]
public void deleteAll(string id)
{
(new announcesBLL()).Delete(Convert.ToInt32(id));
ToIO.Delete("../shtml/view/View_" + id + ".shtml");
}
}贴错
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}function checkuser(){
createXMLHttpRequest();
var a= document.getElementById("txt").value;
url = "Handler/a.ashx?a=" + a+ "&t=" + (new Date()).getTime();
xmlHttp.open("GET", encodeURI(url), true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
}
}
xmlHttp.send(null);
}