search

Home  >  Q&A  >  body text

I am doing a project according to the video course, but the information in the registration form cannot be submitted using a.jax. Please give me an answer.

$(function(){

$("#register").on('click',function (){

alert($('#login').serialize ());

                                                                                                                                                            / //Request address

// url: "{:url('index/user/insert')}",

// //Submit form data

// data: $('#login').serialize(),

// //Returned data type

// dataType: 'json',

// success:function(data){

// alert('successful');

// },

// error:function(data){

                                                                                                     

## })

          </script>

public function insert()

{

// Determine whether the request is an Ajax request

if (Request::isAjax()){

//Use the model to create data

//Get the data submitted by the user through the form Data (except confirm password)

$data = Request::except('password_confirm','post');

//Add data and determine whether it is successful

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

return ['status'=>1,'message'=>'Congratulations, registration successful'];

}else{

return ['status'=>0,'message'=>'Registration failed, please check all data carefully'];

}

}else {

$this->error("Request type error",'register');

}

}

P粉170622230P粉170622230818 days ago1113

reply all(2)I'll reply

  • Sanys

    Sanys2022-12-09 19:05:42

    Check the front-end console to see if the request information of your post is correct?

    Or use dump on the backend to print the requested data

    reply
    0
  • Cancelreply