Ajax的简单用例

<% @ Page Language = " VB "  AutoEventWireup = " false "  CodeFile = " Default.aspx.vb "  Inherits = " _Default "   %>

<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >

< html xmlns = " http://www.w3.org/1999/xhtml "   >
< head runat = " server " >
    
< title > Untitled Page </ title >
    
< link href = " StyleSheet.css "  rel = " stylesheet "  type = " text/css "   />
    
< script language = " javascript "  type = " text/jscript " >
        
// 检测浏览器,创建xmlhttp-request对象
        function getXMLRequester()
        
{
            var xmlhttp_request 
= false;
            
try
            
{
                
if(window.ActiveXObject)
                
{
                    
for(var i = 5;i;i--)
                    
{
                        
try
                        
{
                            
if(i==2)
                            
{
                                xmlhttp_request 
= new ActiveXObject("Microsoft.XMLHTTP");
                            }

                            
else
                            
{
                                xmlhttp_request 
= new ActiveXObject("Msxml2.XMLHTTP" +i+"0");
                                xmlhttp_request.setRequestHeader(
"Content-Type","text-xml");
                                xmlhttp_request.setRequestHeader(
"Content_Type","gb2312");                                
                            }

                            
break;
                        }

                        
catch(e)
                        
{
                            xmlhttp_request
=false;
                        }

                    }

                }

                
else if(window.XMLHttpRequest)
                
{
                    xmlhttp_request 
= new XMLHttpRequest();
                    
if(xmlhttp_request.overrideMineType)
                    
{
                        xmlhttp_request.overrideMineType(
"text/xml");
                    }

                }

            }

            
catch(e)
            
{
                xmlhttp_request 
= false;
            }

            
return xmlhttp_request;
        }

        
        function IDRequest(n)
        
{
            url 
= n + document.getElementById("txtUserID").value;//定义网址参数
            
            xmlhttp_request 
= getXMLRequester();
            xmlhttp_request.onreadystatechange 
= doContents;//调用doContent函数;
            xmlhttp_request.open("Get",url,true);
            
            xmlhttp_request.send(
null);
        }

        
        function doContents()
        
{
            
if(xmlhttp_request.readyState == 4)//收到完整的服务器响应
            {
                
if(xmlhttp_request.status == 200)//Http服务器响应ok
                    document.getElementById("message").innerHTML = xmlhttp_request.responseText;//服务器响应的值
                else
                    alert(http_request.status);
            }

        }

</ script >
</ head >
< body >
    
< form id = " form1 "  runat = " server " >
    
< div >
        
< input type = " text "  id = " txtUserID "  style = " font-size:12px; "   />
        
< input type = " button "  id = " btnOk "  value = " 校验 "  style = " font-size:12px "  onclick  = " IDRequest('http://reg.163.com/register/checkssn.jsp?username=') "   />
        
< div id = " message " ></ div >
    
</ div >
    
</ form >
</ body >
</ html >
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值