gary 2007-9-4 23:39
请教,现在流行AJAX 提交表单,怎么作?
请教,现在流行AJAX 提交表单,象下面那样。
http://cristian.nexcess.net/ajax/validate
谁搞的定,或是你有更高级的东西,我免费送一个CN 或 com.cn 或 net.cn 新网 域名 一年 (事前检查好有没有注册)
:)
robin 2007-9-5 09:50
这个东西很难吗?我虽然没有学过AJAX,不过我想我要是去学,应该不难的。
同样也和你说,不要指望别人,要靠自己去学。
leo 2007-9-5 11:14
相当简单的东西,不过ajax不怎么使用,成不了大气,现在ajax热已经退了,一切又恢复正常了!
gary 2007-9-5 12:30
我是一个PHP新手,搞不到代码 可以参考!
我作的 提交表单 想完美一下(最大的问题,就是什么都没有,就可以过)
robin 2007-9-5 13:34
提交表单不是最重要的
最重要是处理这个提交表单的程序
所以说 你要学的是PHP 不要因为皮毛而丢了骨肉啊
chenyang2005 2007-9-6 10:00
好象 JS 实现的功能更复杂些
gary 2007-9-8 11:14
好,谢谢楼上的帮助,要域名的 跟帖 留下 email
风过无语 2007-9-8 12:10
AJAX使用的是不多`因为掌握这个技术的人都很少
但是是一个很有用的东西哦,在需要实时刷新的时候就可以看到它的好处
不过我现在开发网站几乎很少有用这个~`用到时候我都是直接去偷的
JS也用比较多~~
不懂 2007-9-10 09:52
呵呵 ``` 路过观光下 .....继续 学习....
傲慢的上校 2007-9-20 23:50
偶开始学时做电话本用到了点,贴出来了额...^_^
UserShow.php
[code]
<?
header("Cache-Control: no-cache, must-revalidate");
?>
<script type="text/javascript" src="../include/prototype.js"></script>//prototype.js一个表单和js交互的东东,很不错的还有帮助此例子中未用
<script type="text/javascript" src="showusers.js"></script>
<body onload='process()'>
<div id="username">name</div>
<div id="showphoto">photo</div>
</body>
[/code]
showusers.js
[code]
var xmlHttp = createXmlHttpRequestObject();//创建对象
function createXmlHttpRequestObject()
{
var xmlHttp;
if(window.ActiveXObject)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
xmlHttp = false;
}
}
else
{
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
xmlHttp = false;
}
}
if (!xmlHttp)
alert("Error creating the XMLHttpRequest object.");
else
return xmlHttp;
}
function process()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
//name = encodeURIComponent(document.getElementById("myName").value);
xmlHttp.open("GET", "showusers.php?fresh="+Math.random(), true); //为什么加任意参数fresh="+Math.random(),反正这么加才会响应get方法,要不请求无效
xmlHttp.onreadystatechange = handleServerResponse;//调用方法
xmlHttp.send(null);
}
else
setTimeout('process()', 1000);
}
function handleServerResponse()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200) //请求返回完成
{
xmlResponse = xmlHttp.responseXML;//得到请求创建对象下面开始读取
xmlDocumentElement = xmlResponse.documentElement;
//helloMessage = xmlDocumentElement.firstChild.data;
var num=xmlResponse.getElementsByTagName("username").length;
//source.async=false;
var showusername="";
var showphoto="";
var id="";
for(i=0;i<num;i++)//循环从返回的请求中读取数据
{
id = xmlResponse.getElementsByTagName("id").item(i).firstChild.nodeValue;
var username = xmlResponse.getElementsByTagName("username").item(i).firstChild.nodeValue;
// helloMessage="uploads/"+helloMessage;
var photo=xmlResponse.getElementsByTagName("photo").item(i).firstChild.nodeValue;
photo="uploads/"+photo;
//alert(num);
showusername = showusername+'<i>'+username+'</i>';
showphoto=showphoto+'<a href="UsersModify.php?id='+id+'" target="_self">修改</a> <a href="UsersDel.php?id='+id+'" target="_self">删除</a><img src="'+photo+'" width="132" height="179">';
//alert(showphoto);
// document.getElementById("showphoto").innerHTML = '<img src="'+photo+'" width="132" height="179">';
}
document.getElementById("username").innerHTML = '<i>'+showusername+'</i>';
document.getElementById("showphoto").innerHTML = showphoto;
setTimeout('process()', 5000);//五秒后再次请求,其实这是个笨方法,呵呵
}
else
{
alert("There was a problem accessing the server: " + xmlHttp.statusText);
}
}
}
[/code]
showusers.php//php构造xml文件
[code]
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="gb2312" standalone="yes"?>';
require_once '../include/conn.php';
echo '<response>';
$sql = "select * from users";
$query = mysql_query($sql,$myconn);
$query1 = mysql_query($sql,$myconn);
$num = mysql_num_rows($query);
//mysql_data_seek($query ,0);
$username="";
if($num<>0)
{
while($rec=mysql_fetch_array($query1))
{
$username=$rec["username"];
echo "<id>";
echo $rec["id"];
echo "</id>";
echo "<username>";
echo $rec["username"];
echo "</username>";
echo "<photo>";
echo $rec["picture"];
echo "</photo>";
}
}
//echo htmlentities($username);
echo '</response>';
?>
[/code]
傲慢的上校 2007-9-20 23:59
Ajax and Php四月份人民邮电翻译的那本所有的例子和电子版的
111
[[i] 本帖最后由 傲慢的上校 于 2007-9-21 00:00 编辑 [/i]]