大连中远川崎地址:Ajax 中表单数据提交问题

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 05:50:19
XMLHttpRequest 中(假设有一实例 xml = new XMLHttpRequest(); 且脚本在客户端)
对象有一个方法为:open(method, url, ayncflag);

假设在一HTML文件中有一个表单,
表单中有用户名(username)与密码(userpass)两个文本框。

现在问题就是:
我要进行注册,填写好用户名及密码后,
如何在客户端设用javascript将数据提交到服务器?

我是这么写的:
xml.open('POST', 'register.php', true);
xml.send("username=" + username.value + "&userpass=" + userpass.value);
可是在服务器端,$_GET,$_POST中都没有接收到对应的数据……

是不是一定要在服务器端使用XML解析才能收到数据?

这个问题想得头都快炸了……

在网上找到的都是:
xml.open('GET', 'register.php?username=**&userpass=**", true);

xml.open('POST', 'register.php', true);
xml.send("<xml><user>**</user><pass>**</pass>");

越说越不清楚了!

简单的说就是,我希望能直接在客户端写
xml.open('POST', 'register.php', true);
xml.send("username=" + username.value + "&userpass=" + userpass.value);
而在服务器端使用 $_POST 来提取提交的数据!

请指教!