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