Home>Article>Backend Development> ajax form submission operation in thinkPHP5

ajax form submission operation in thinkPHP5

不言
不言 Original
2018-06-07 15:57:40 3223browse

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:

       
  

In fact, it is no different from normal ajax. It mainly uses jquery’sserialize()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); } }

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

Form submission and passing parameters:

Obtain

$project_name=input("post.project_name");

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

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

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!

Statement:
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