Home > Backend Development > PHP Tutorial > 注册页面对应的函数得不到文本控件的值

注册页面对应的函数得不到文本控件的值

WBOY
Release: 2016-06-23 13:48:22
Original
1002 people have browsed it

注册页面对应的函数:

$.post('{:U("Register/register")}', $('#register'), function(str) {     //  .serialize()
Copy after login


RegisterAction.class.php 中:
//注册    public function register() {         $data['u_username'] = strtolower(I('name', '', 'trim'));        $data['u_phone'] = I('phone', '', 'trim');        $data['u_email'] = I('email', '', 'trim');        $data['u_password'] = I('pass');        $data['repassword'] = I('rpass');        $rpass = I('rpass');        ... ...
Copy after login

这几个变量得到的值都是空的,为什么呢?

在register模板文件中,
if (email === 0 || phone === 0 || code === 0 || username === 0 || password === 0 || rpassword === 0) {...
Copy after login

这几个email等变量的值都是0

if (document.getElementById("email").value === 0 || document.getElementById("phone").value === 0 || document.getElementById("code").value === 0 || document.getElementById("username").value === 0 || document.getElementById("password").value === 0 || document.getElementById("rpassword").value === 0) {
Copy after login

改成这样就都取到各个文本框控件的值了。

文本框代码:
<input  name="email" id="email" maxlength="30" />
Copy after login


回复讨论(解决方案)

如果 register 是表单的id
那么
$.post('{:U("Register/register")}', $('#register') .serialize(), function(str) { .......

是THINKPHP框架的项目噢!

如果 register 是表单的id
那么
$.post('{:U("Register/register")}', $('#register') .serialize(), function(str) { .......



谢谢回复!奇怪的是,改成这样就没去执行RegisterAction.class.php 中的register()了!

这是为什么呢?

别的类似的ajax都触发了,为什么这句AJAX无法被触发呢?百思不得其解!

前面说得不对,有触发AJAX,返回这个怪怪的字符串,也不知道哪里来的: {"info":"\u9a8c\u8bc1\u7801\u8f93\u5165\u9519\u8bef!","status":0,"url":""}
应该返回1或“注册失败,请重试!”才对啊!奇怪!

if ($status && $status2 && $status1 && $status3) {            $m->commit();            unset($_SESSION['thirdPartyUserId']);            unset($_SESSION['thrid_party_type']);            $_SESSION['uname'] = $data['u_username'];            die("1");        } else {            $m->rollback();            die("注册失败,请重试!");        }
Copy after login

print_r(json_decode(' {"info":"\u9a8c\u8bc1\u7801\u8f93\u5165\u9519\u8bef!","status":0,"url":""}'));

stdClass Object
(
    [info] => 验证码输入错误!
    [status] => 0
    [url] => 
)

你没按规矩来!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template