页面用ajax实现简单的连接数据库
(1)?寫發(fā)送代碼
var myXmlHttpRequest = "";
myXmlHttpRequest = getXmlHttpRequest();
??????????? if (myXmlHttpRequest) {? //xmlHttpRequest創(chuàng)建成功了,才能發(fā)送請求
??????????????? //地址一定要寫正確
??????????????? var url = "../zhuCe/zhuCeYanZheng.aspx?username=" + $('Text1').value;
??????????????? myXmlHttpRequest.open("get",url,true);
??????????????? myXmlHttpRequest.onreadystatechange = getData;
??????????????? myXmlHttpRequest.send(null);
??????????? }
(2)?寫接受數(shù)據(jù)代碼:
function getData() {
??????????? if((myXmlHttpRequest.readyState == 4) && (myXmlHttpRequest.status == 200)){
??????????????? //alert("nihao");
??????????????? var returnMessage = myXmlHttpRequest.responseText;
??????????????? //alert(returnMessage);
??????????????? if (returnMessage == "用戶名不正確"){
??????????????????? alert("aaa");
??????????????? }
??????????? }??
??????? }
(3)另外需要加兩個函數(shù)
function getXmlHttpRequest() {
??????????? var xmlHttpRequest;
??????????? if(window.ActiveXObject){
??????????????? xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
??????????? }else{
??????????????? xmlHttpRequest = new xmlHttpRequest();
??????????? }
??????????? return xmlHttpRequest;
??????? }
???????
function $(id) {
??????????? return document.getElementById (id);
??????? }
?
轉(zhuǎn)載于:https://blog.51cto.com/5155796/1095475
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產(chǎn)品紅包拿不停!總結(jié)
以上是生活随笔為你收集整理的页面用ajax实现简单的连接数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: POJ 1979 Red and Bla
- 下一篇: SQL Server的导出导入方式有