註冊頁面對應的函數得不到文本控制項的值

來源:互聯網
上載者:User
註冊頁面對應的函數:
$.post('{:U("Register/register")}', $('#register'), function(str) {     //  .serialize()


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');        ... ...

這幾個變數得到的值都是空的,為什麼呢?

在register模板檔案中,
if (email === 0 || phone === 0 || code === 0 || username === 0 || password === 0 || rpassword === 0) {...

這幾個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) {

改成這樣就都取到各個文字框控制項的值了。

文字框代碼:


回複討論(解決方案)

如果 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("註冊失敗,請重試!");        }

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

stdClass Object
(
[info] => 驗證碼輸入錯誤!
[status] => 0
[url] =>
)

你沒按規矩來!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.