ajax form submission operation in thinkPHP5

不言
Release: 2023-03-30 14:06:01
Original
3149 people have browsed it

This article mainly introduces the thinkPHP5 ajax form submission operation, and analyzes the ajax submission form operation skills of thinkPHP5 in the form of examples, and also explains the parameter transfer and processing skills in form submission. Friends who need it can refer to it

The example in this article describes the thinkPHP5 ajax form submission operation. Share it with everyone for your reference, the details are as follows:



  
    
    
    
    
  
  
    

Copy after login

In fact, it is no different from normal ajax. It mainly uses jquery’s serialize() method to serialize the form

In the middle I encountered some troubles because I am not familiar with the thinkphp5 framework. I have not had time to use 3.2.3 before. There are still some differences between the two versions.

One is that $_POST cannot be used, and the original ajax url can be used. The U method of the framework is gone. I looked specifically at the assistant function under think and found that it is url

The following is a random method for returning json data

public function test($mess,$id){
    if($mess == '123'){
      return json("ajax成功!".$mess."---".$id);
    }else{
      return json("你输出的是其他值:".$mess."---".$id);
    }
}
Copy after login

In addition, the regular parameter submission and The processing method is as follows:

Form submission and passing parameters:

Copy after login

Obtain

$project_name=input("post.project_name");
Copy after login

in the controller and jump to the passing parameters in php:

$this->success('新增项目成功',url("Version/index",array('project_name'=>$project_name)));
die;
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Analysis of form token errors and solutions under ThinkPHP

Using ajax to achieve zero in Thinkphp Method of refreshing paging

ThinkPHP and Ajax implement secondary linkage drop-down menu

The above is the detailed content of ajax form submission operation in thinkPHP5. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!