3月 28
Asynchronous JavaScript + XML(Ajax)无疑是 2006 年最热门的技术术语。

阅读一下内容,您首先需要知道:
1、Ajax 仅仅是一个涉及一组技术的术语,包括 Dynamic HTML(DHTML)和 XMLHTTPRequest 对象
2、DHTML 由三个元素组合而成,它们分别是超文本标记语言HTMLJavaScript 代码和级联样式表CSS
3、在 Web 页面使用 JavaScript 代码,可以动态地改变页面,包括添加、删除或更改页面内容。这就是 DHTML 的动态 部分。
4、JavaScript 代码使用 XMLHTTPRequest 对象在加载页面后向服务器请求数据。
5、从服务器动态请求数据然后使用这些数据更改页面 —— 就是 Ajax 的本质,也是 Web 2.0 站点的动态特性。

下面,介绍几种AJAX的设计模式,它们在使用 HTML、XML 和 JavaScript 代码从服务器获取数据方面有所不同。我先介绍最简单的模式,它将使用来自服务器的新 HTML 页面来更新页面。

模式 1. 替换 HTML 片段
最常见的 Ajax 任务也许就是向服务器请求更新的 HTML 并使用它更新部分页面。可能需要周期性地完成这一任务 —— 比如,更新股市报价。也可能要按需更新 —— 比如,对搜索请求进行响应。
Tags: , , , , ,
2月 16
使用php、ajax的功能,实现前面输入邮件地址,后边动态的显示输入的字符。
php页面用来处理想实现的业务,比如验证邮件有效性等,便于扩展。
点击在新窗口中浏览此图片

HTML部分:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
<form action="" method="post">
<table border="1" width="100%">
<tr><td height="30">
邮箱是:<input type="text" name="eMail"  id="eMail"  onKeyUp="valideMail();">
<span id="show"></span>
</td></tr>
</table>
</form>
</body>
</html>

实现的javascript部分:
<script language="javascript">
var xmlHttp;
function valideMail() {
 var email = document.getElementById("eMail");
 var url = "mail.php?email=" + email.value;
 if (window.ActiveXObject) {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 } else if (window.XMLHttpRequest) {
  xmlHttp = new XMLHttpRequest();
 }  
 xmlHttp.onreadystatechange = callBack;
 xmlHttp.open('GET', url, true);  
 xmlHttp.send(null);
}

function callBack() {
 if (xmlHttp.readyState == 4) {
  if (xmlHttp.status == 200) {
   document.getElementById("show").innerHTML = "show:" + xmlHttp.responseText;
  }
 }
}
</script>

返回值的PHP页mail.php
<?php
$email = $_GET["email"];
if ($email == "") {
 $email = "rrrrrrrrrrrrrrrrrr !";
}
echo ($email);
exit(0);
?>

为了让页面在更改的时候保持刷新,可以在php中添加下面代码
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
Tags: , ,
2月 14
ajax现在越来越火,大家使用中常遇到的就是中文乱麻了

如果传送参数是直接赋予的,就会产生乱码!
http_request.open("POST",url,true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send("action="+strName+"&val="+val);   //如果val的值为中文,则产生乱码


解决方法很简单:使用javascript中的escape(string) 函数
http_request.open("POST",url,true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send("action="+strName+"&val="+escape(val));   //val的值为中文不会产生乱码 (unescape(val))就可以解码
Tags: ,
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]