0

我在同一页面上查看了登录和注册表单。我想只返回错误消息而不刷新整个页面。我怎样才能做到这一点?

public function signup() {      

        $this->form_validation->set_rules('user_name', 'User name', 'min_length[4]|is_unique[ts_user.user_name]|xss_clean');
        $this->form_validation->set_rules('user_twitter_id', 'User Twitter ID', 'is_unique[ts_user.user_twitter_id]|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[ts_user.email]');

        if($this->input->post('submit') == TRUE) {
            if($this->form_validation->run()) {
                $twitterid = $this->input->post('user_twitter_id');
                $username = $this->input->post('user_name');
                $email = $this->input->post('email');
                $password = $this->input->post('password');

                $this->Usermodel->add_user($twitterid, $username, $email, $password);
                echo 'Successful.';
            } else {
                echo validation_errors();
                /*$this->load->view('registration_view');*/
            }
        }
    }
4

1 回答 1

0

不要使用post,使用ajax

样本:

var paperData = 'name=' + sourceFileName + '&' + 'file=' + uploadFileName;
 var url = encodeURI('/Paper/Create?' + paperData);
            ajax

            ({

                block: false,

                url: url,

                success: function (r) {

                    if (r.success) {

                                    var html='<tr><td class="tac">';

                                        html = html + r.displayName;

                                        html = html + '</td>';

                                        html = html + '<td class="tac">';

                                        html = html + r.type;

                                        html = html + '</td>';

                                        html = html + '<td>';

                                        html = html + '<a class="showPaperEditor" href="/Paper/Edit/';

                                        html = html + r.paperID;

                                        html = html + '" w="570" h="340" >修改</a>';

                                        html = html + '<span class="cd">┊&lt;/span>' ;

                                        html = html + '<a class="a-ajax-delPaper" href="/Paper/Delete/';

                                        html = html + r.paperID;

                                        html = html + '">删除</a>';

                                        html = html + '</td></tr>';



                                    $('#tbPaperList').append(html);

                    }

                    else {

                        alert(r.message);

                        //$.unblockUI();

                    }

                }

            });
于 2012-06-20T04:13:56.960 回答