Home  >  Q&A  >  body text

I failed to follow the teacher’s instructions

register.html file

<script>
$(function () {
$("#register").on('click',function () {
// Alert ($ ('#login'). Serialize ());
$ .ajax ({
Type: 'Post',
URL: "{: URL ('Index/User/Insert ')}",
                                                                                                                                                                                      using           using   using           use using ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ dataType:'json',
                                           ' ;
##{

if(Request::isAjax()){

//Use the model to create data
//Get the data submitted by the user through expression
$data = Request::except('password_confirm','post');

if(UserModel::create($data)){

return ['status' => 1,'message'=>'Register Success'];

        }else{

              return ['status' => 0,'message' =>'Registration failed'];
                                            using   using     using using       using using using through out through out out out out out out out of ''''''‐to ‐‐‐‐‐‐‐‐‐‐ ->error("Request type error",'register');
}
}

May I ask the teacher why there is no response when submitting, and the database is not successfully added

白月光 °白月光 °2371 days ago1582

reply all(9)I'll reply

  • 呼啦啦下雨天

    呼啦啦下雨天2019-06-11 08:52:44

    You can directly reference think/Db in User.php and use Db to insert data

    reply
    0
  • 时光

    时光2018-09-30 22:01:07

    My problem is the same as yours. I just changed the ajax submitted path {url('insert')} to an absolute path. I don't know why.

    reply
    0
  • 鱼越龙门

    Brother, how did you write it? I followed the video but failed. I couldn't insert data into the database.

    鱼越龙门 · 2018-12-18 22:48:04
  • JonnyZhu

    JonnyZhu2018-08-10 16:19:54

    data: $('#login').serializeArray(), details the serializeArray() method to serialize form elements (similar to the .serialize() method) and return JSON data structure data. Note: This method returns a JSON object rather than a JSON string. The website is here: http://www.w3school.com.cn/jquery/ajax_serializearray.asp

    reply
    0
  •  Jensen

    Jensen 2018-06-20 10:27:04

    Hello, I have the same problem, how can I solve it?

    reply
    0
  • plhxz

    plhxz2018-06-11 02:49:16

    Have you succeeded now? I have the same problem

    reply
    0
  • 路过

    路过2018-03-28 08:22:06

    1. Make sure you have introduced jquery

    2. Make sure ajax has passed the data

    3. Background php receives data

    4. There are databases, tables, and fields corresponding to the data you added

      I can only help you so far

    reply
    1
  • 白月光 °

    It is confirmed that jquery is introduced, data is transmitted through ajax, and the data transmitted by ajax is received in the background. However, the create function neither reports an error nor succeeds, and there is no response.

    白月光 ° · 2018-03-28 14:46:44
    凌晨¤

    Did you succeed? I also encountered this problem. Alas.

    凌晨¤ · 2018-08-01 14:14:16
  • Cancelreply