加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

5.页面用ajax实现简单的连接数据库

发布时间:2020-12-16 00:28:32 所属栏目:百科 来源:网络整理
导读:(1)写发送代码 var myXmlHttpRequest= "" ; myXmlHttpRequest=getXmlHttpRequest(); if (myXmlHttpRequest){ //xmlHttpRequest 创建成功了,才能发送请求 // 地址一定要写正确 var url= "../zhuCe/zhuCeYanZheng.aspx?username=" +$( 'Text1' ).value; myX

(1)写发送代码

varmyXmlHttpRequest="";

myXmlHttpRequest=getXmlHttpRequest();

if(myXmlHttpRequest){//xmlHttpRequest创建成功了,才能发送请求

//地址一定要写正确

varurl="../zhuCe/zhuCeYanZheng.aspx?username="+$('Text1').value;

myXmlHttpRequest.open("get",url,true);

myXmlHttpRequest.onreadystatechange=getData;

myXmlHttpRequest.send(null);

}

(2)写接受数据代码:

functiongetData(){

if((myXmlHttpRequest.readyState==4)&&(myXmlHttpRequest.status==200)){

//alert("nihao");

varreturnMessage=myXmlHttpRequest.responseText;

//alert(returnMessage);

if(returnMessage=="用户名不正确"){

alert("aaa");

}

}

}

(3)另外需要加两个函数

functiongetXmlHttpRequest(){

varxmlHttpRequest;

if(window.ActiveXObject){

xmlHttpRequest=newActiveXObject("Microsoft.XMLHTTP");

}else{

xmlHttpRequest=newxmlHttpRequest();

}

returnxmlHttpRequest;

}

function$(id){

returndocument.getElementById(id);

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读