喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: 问一个ajax的问题  
 
sq1228
中级会员
Rank: 3Rank: 3
一般会员


UID 66008
精华 0
积分 267
帖子 239
金钱 267 喜悦币
威望 0
人脉 0
阅读权限 30
注册 2005-8-19
来自 浙江宁波
状态 离线
问一个ajax的问题

问一下有没有对ajax操作类???
2006-7-17 04:35 PM#1
查看资料  发短消息  QQ . .   顶部
 
风在芯中
金牌会员
Rank: 6Rank: 6
kuliu.com



UID 25808
精华 0
积分 2548
帖子 716
金钱 2548 喜悦币
威望 0
人脉 0
阅读权限 70
注册 2004-1-19
来自 福建 福州
状态 在线
[推荐阅读] xajax返回404时我怎么处理?
从google拿下的一段很简单的ajax代码
可以学习一下。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>myajax</title>
</head>

<body>
<script>
//-----------------------------------
//check showbar name
function getState(xmlhttp) {
//alert(xmlhttp.readyState+','+xmlhttp.status);
  if (xmlhttp.readyState != 4) return false;
  if (xmlhttp.status != 200) return false;

  alert(xmlhttp.responseText);

}

//-----------------------------------
// Browser detection
var agt = navigator.userAgent.toLowerCase();

var is_opera = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_opera;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all;

// ----------------------------------
// XML Http requests
function CreateXmlHttpReq(handler) {
  var xmlhttp = null;

  if (is_ie) {
    // Guaranteed to be ie5 or ie6
    var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    try {
      xmlhttp = new ActiveXObject(control);
    } catch(e) {
      // TODO: better help message
      alert("You need to enable active scripting and activeX controls");
      DumpException(e);
    }
  } else {
    // Mozilla
    xmlhttp = new XMLHttpRequest();
  }
  xmlhttp.onreadystatechange = function() {
    handler(xmlhttp);
  }
   
  return xmlhttp;
}

var uniqnum_counter = (new Date).getTime();
function UniqueNum() {
  ++uniqnum_counter;
  return uniqnum_counter;
}

// Send a (hidden, non blocking) update message to the server
// by sending a xmlhttp request
function SendServerRequest(url) {
  StartGETRequest(url, function() {});
}

//
function CheckRequest(url) {  
  StartGETRequest(url, getState);
}

// Send a request to the server
function StartGETRequest(url, handler) {
  var xmlhttp = CreateXmlHttpReq(handler);
  xmlhttp.open('GET', url + "&rand=" + UniqueNum(), true);
  xmlhttp.send(null);
}

// Send a post request to the server
function StartPOSTRequest(url, data, handler) {
  var xmlhttp = CreateXmlHttpReq(handler);
  xmlhttp.open('POST', url, true);
  xmlhttp.send(data);
}

//-->
</script>

<script>
function post(state){
  //if (state == 1) {
  //  SendServerRequest("http://127.0.0.1/myajax/passive.php?state=off");
  //} else {
  //  SendServerRequest("http://127.0.0.1/myajax/passive.php?state=on");
  // }
  if(!CheckRequest("http://192.168.1.210/myajax/passive.php?state=on"))
  return false;
}
</script>


<a onclick="return post(0);">click here</a>
</body>
</html>




酷溜网
2006-7-17 04:58 PM#2
查看资料  访问主页  Blog  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.021681 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP